Structure of C
Structure of C
C language does not actually follow any specific method of writing a program. It is a case sensitive language.
All the statements must be written in lower case letters (small letters). The structure of a C program is as
follows:-
Main Function Header File
<Header file> #include<stdio.h>
<Global declaration of variable> #include<conio.h>
main ( )
{ int main ( )
<local declaration of variables> { Main Block Start
---------------------------------
<statements> Function
-------------------------------- printf(“ Hello World”); and
} return 0; Statements
<sub-programs- function blocks>
} Main Block End
Comments
Structure of C
/* Structure of C*/
Header File
Global Variable #include<stdio.h>
#include<conio.h>
int a ;
Main Function main ( )
Main Block Start
{
int b, sum;
Local Variable
clrscr ( );
printf(“ \n Enter Value to A:”);
scanf(“ %d”, &a); Function
printf(“ \n Enter Value to B:”); and
scanf(“ %d”, &b);
Statements
sum = a+b;
printf(“ \n SUM = %d”, sum);
getch ( );
} Main Block End
Other Functions
• The header files or preprocessor directives give instructions to the complier to include complier
option (#include), macro substitution (#define) to substitute a constant for an identifier and
conditional (#ifdef) directives.
• The main statement block, function block and other blocks used in a C program are enclosed in
braces { }.
• Variable declared outside main ( ) are called global variables and they can be used in the main
program block and sub program block.
• Variables declared inside main ( ) are called local variables, and they are used only in block in
which they are declared. Sub program/function can also have local variables.
• Any C program has coding in the form of letters and symbols. Normally documentation to the
program is made by adding remarks or comment lines enclosed in /* and */ whenever necessary.
Output of Program
Enter Value to A: 5
Enter Value to B: 3 Input Value
SUM = 8 Output