In the previous tutorial we learnt Rules for writing a 'C' Program.In this tutorial we will learn the Structure of C Program.The C program is the collection of instruction,and instruction is nothing but the statements in C.
Structure of C Program
#include<pre-processor directives> [macro declaration and definition] [global variable declaration] main() { local variable declaration with proper data type; : : statements; : : } [ user_defined_function_definition (arguments)] { statement_block; } ]
Explanation:
#include<pre-processor directives>:[Macro declaration and definition]:
At this place we have to declare and define the definitions of the macro that are used in program.
It is optional.
[Global variable declaration]:
If we required global variables in our program then such variables are declared at this place.It is optional.
main():
This is the first statement of every 'C' program,without main() function 'C' program cannot be start.If we didn't include main() function in 'C' program then error will be occurred.So Every 'C' program must start with main() function.
Local variable declaration:
At this place we have to declare all the variables with proper data type,which are used in our program (in main() function).
Statements:
At this place, we have to write all the statements,which are used to solve the aim of program.
[User-defined-function-definition]:
If any user defined function is called in program,then its definition are given at this place.It is optional.
Example:
#include<stdio.h> #include<conio.h> main() { int a,b; clrscr(); printf("Enter value of a and b "); scanf("%d %d",&a,&b); printf("Sum=%d",a+b); getch(); }
0 comments:
Post a Comment