IT & Software Exam  >  IT & Software Notes  >  Programming in C (part 1)

Programming in C (part 1) - IT & Software PDF Download

PROGRAMMING AND DATA STRUCTURES PROGRAMMING
IN C
C is a general-purpose high level language that was originally developed by Dennis
Ritchie for the Unix operating system. It was first implemented on the Digital
Equipment Corporation PDP-11 computer in 1972.
The Unix operating system and virtually all Unix applications are written in the C
language. C has now become a widely used professional language for various
reasons.
• Easy to learn
• Structured language
• It produces efficient programs.
• It can handle low-level activities.
C Program File
All the C programs are writen into text files with extension ".c" for example hello.c.
You can use "vi" editor to write your C program into a file.
This tutorial assumes that you know how to edit a text file and how to write
programming insturctions inside a program file.
C Compilers
When you write any program in C language then to run that program you need to
compile that program using a C Compiler which converts your program into a
language understandable by a computer. This is called machine language (ie. binary
format). So before proceeding, make sure you have C Compiler available at your
computer. Preprocessor Commands
• Functions
• Variables
• Statements & Expressions
• Comments
The following program is written in the C programming language. Open a text file
First.c using vi editor and put the following lines inside that file.
#include <stdio.h>
int main()
{
 /* My first program */
 printf("This is a C program! \n");
 return 0;
}
Preprocessor Commands: These commands tells the compiler to do preprocessing
before doing actual compilation. Like #include <stdio.h> is a preprocessor command
which tells a C compiler to include stdio.h file before going to actual compilation.
Functions: are main building blocks of any C Program. Every C Program will have one
or more functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function returns
an integer value when it exits. This integer value is returned using return
statement.The C Programming language provides a set of built-in functions. In the
above example printf() is a C built-in function which is used to print anything on the
screen.
Variables: are used to hold numbers, strings and complex data for manipulation.
Statements & Expressions : Expressions combine variables and constants to create
new values. Statements are expressions, assignments, function calls, or control flow
statements which make up C programs.
Comments: are used to give additional useful information inside a C Program. All the
comments will be put inside /*...*/ as given in the example above.
Note the followings

• C is a case sensitive programming language. It means in C printf and Printf
will have different meanings.
• C has a free-form line structure. End of each C statement must be marked
with a semicolon.
• Multiple statements can be one the same line.
• White Spaces (ie tab space and space bar ) are ignored.
• Statements can continue over multiple lines.
C - Reserved Keywords
The following names are reserved by the C language. Their meaning is already
defined, and they cannot be re-defined to mean anything else.
Auto else Long switch
Break enum register typedef
Case extern return union
Char float Short unsigned
Const for signed void
Continue goto Sizeof volatile
Default if Static while
Do int Struct Packed
Double
While naming your functions and variables, other than these names, you can choose
any names of reasonable length for variables, functions etc.
C Preprocessor, Directives and Header Files:
C Preprocessor :
As part of compilation, the C compiler runs a program called the C preprocessor. The
preprocessor is able to add and remove code from your source file. One of the major
functions of C preprocessor is Tokenizing. The final step of the preprocessor is to
link the resulting program with necessary programs and library.
This directive is used for text substitution. Every occurrence of the identifier is
substituted by the substitution_token. The primary advantage is that it increases the
readability of the program.
# include directive:
This directive searches for a header or source file, which can be processed by the
implementation, to be include in the program.
Header files:
Header files are a collection of macros, types, functions and constants. Any program
that needs those functions can include the corresponding header files.
List of some commonly used Header file and their purposes:
Header Files Purpose Functions Declared

Header Files Purpose Functions Declared
stdio.h Used for standard input and output (I/O) 
operations.
printf(), scanf(), getchar(), 
putchar(), gets(), puts(), getc(), 
putc(), fopen, fclose(), feof()
conio.h Contains declaration for console I/O 
functions
clrscr(); exit()
ctype.h Used for character-handling or testing 
characters.
isupper(), is lower, isalpha()
math.h Declares mathematical functions and 
macros
pow(), squr(), cos(), tan(), sin(), 
log()
stdlib.h Used for number conversions, storage 
allocations.
rand(), srand()
string.h Used for manipulating strings streln(), strcpy(), strcmp(), stract(), 
strlwr(), strupr(), strrev()

Syntax :
#define directive:
#define identifier substitution_token
For Example:
#define TRUE 1
#define FALSE
#define MAX 100
#define PI 3.14
Syntax :
#include <filename>



The document Programming in C (part 1) - IT & Software is a part of IT & Software category.
All you need of IT & Software at this link: IT & Software
Download as PDF

Top Courses for IT & Software

Related Searches

MCQs

,

Programming in C (part 1) - IT & Software

,

ppt

,

Programming in C (part 1) - IT & Software

,

study material

,

mock tests for examination

,

video lectures

,

shortcuts and tricks

,

Important questions

,

Extra Questions

,

Semester Notes

,

practice quizzes

,

Programming in C (part 1) - IT & Software

,

Viva Questions

,

Summary

,

Previous Year Questions with Solutions

,

Objective type Questions

,

Exam

,

Sample Paper

,

Free

,

past year papers

,

pdf

;