Chapter 1 C Programming
Chapter 1 C Programming
History of C:
✓ The C programming language was designed by Dennis
Ritchie at Bell Laboratories in the early 1970s
All sections, except the main function section may be absent when they are not required
Documentation section:
Consists of a set of comment lines like name of the
program, the author
Link section:
Provides instructions to the compiler to link functions from
the system library
Definition section:
Defines all symbolic constants
Global Declaration section:
Global variable are declared in global declaration section
i.e. outside of all the functions also declares all the user-
defined functions
Cont…
Every C program must have one main() function
It contains two parts
Declaration part
Executable part
Declaration part:
Declares all the variables used in the executable part
Executable part:
At least one statement in this part
These two parts must appear between opening and closing
braces ({ } )
The program execution begins at the opening brace and ends
at the closing braces
The closing brace of the main function is the logical end of
the program
Cont…
Subprogram section:
Contains all the user-defined functions
The functions are called in the main function
Example Program:
/* Name: xxxxx */ Documentation Section
/*Program showing only printf statement*/
#include <stdio.h>
Link Section
#include <conio.h>
#define PI=3.14 Definition Section
int a=10;
void sum(); Global variable declaration Section
main()
Control Starts from here
{
Opening Brace
int count = 1;
Declaration part
printf(“ The pie value is = %f”, PI);
printf(“The value of a is = %d”,a); Executable part
sum();
}
Closing Brace
void sum() Subprogram Section
{ printf(“The value of a is=%d”,a);
Programming Style
Writing program in lowercase letters
C is a free form language, we can group statements
together on one line.
a=b;
x=y+1;
z=a+x;
Can be written in one line as
a=b; x=y+1; z=a+x;
Executing a ‘C’ program
Creating the program
Compiling the program
Linking the program
Executing the program