Structure of ‘C’ Program:
Before understanding the structure of a ‘C’ program you must know these important points:
- ‘C’ is a case sensitive language, it means all the keywords must be written in lower case.
- Key-words can’t be used as a variable or function name.
- Every instruction should end with (;) sign.
- Preprocessor directives (required) should be there in the beginning.
- Function main () is must for a program.
Now to write a program in ‘C’ we need to follow these steps: Define preprocessor directives (include header files according to prototype functions, standard I/O library functions to be used).
- Open function main ()
- Assign data types and variables.
- Define the body of the function
- End the function main ()
Example
/* harsh.c : first example for students */
# include
void main ()
{ int a = 10, b = 15, c;
printf (“Hellow students \n”); c = a + b ;
printf (“The sum of % d and % d is % d” , a, b, }
In the above example the first line /*harsh.c: first example for students */ is a comment and non-executable. Comments in ‘C’ begins with (/*) and ends with (*/).
Second-line
#include
is a preprocessor directive. The preprocessor processes the ‘C’ program before the compiler. Here stdio.h is a header file consists of standard I/O functions. A header file related to the functions used in program should be included at the beginning.
The line void main() indicates “the beginning of the program”. The compilation of the program starts from main () function.
{, the symbol indicates the beginning of the main () function
The line int a = 10, b = 15, C; is for declaration of variables and data types.
Lines
printf (“Hellow students \n”); C = a + b. printf (“The sum of % d and % d is % d” , a, b, c); are the body of the program.
and symbol ‘}’ indicates end of main ( ) function.