Structure of C program

Structure of c program:  

1 ) Comment line 

2) Preprocessor directive 

3 ) Global variable declaration 

4) main function( ) { Local variables; Statements; } User defined function } } Comment line It indicates the purpose of the program. It is represented as /*……………………………..*/ Comment line is used for increasing the readability of the program. It is useful in explaining the program and generally used for documentation. It is enclosed within the decimeters. Comment line can be single or multiple line but should not be nested. It can be anywhere in the program except inside string constant & character constant.

Preprocessor Directive:

#include tells the compiler to include information about the standard input/output library. It is also used in symbolic constant such as #define PI 3.14(value). The stdio.h (standard input output header file) contains definition &declaration of system defined function such as printf( ), scanf( ), pow( ) etc. Generally printf() function used to display and scanf() function used to read value.

Global Declaration:

This is the section where variable are declared globally so that it can be access by all the functions used in the program. And it is generally declared outside the function :

main()

It is the user defined function and every function has one main() function from where actually program is started and it is encloses within the pair of curly braces. 

The main( ) function can be anywhere in the program but in general practice it is placed in the first position. 

Syntax : main() 

{ …….. …….. …….. } 

The main( ) function return value when it declared by data type as 

 int main( ) 

return 0 

}

 The main function does not return any value when void (means null/empty) as void main(void ) or void main() 

 printf (“C language”); 

Output: C language The program execution start with opening braces and end with closing brace. 

And in between the two braces declaration part as well as executable part is mentioned. And at the end of each line, the semi-colon is given which indicates statement termination.

Ex: Program to Display "Hello, World!"

#include <stdio.h>
int main() {
   // printf() displays the string inside quotation
   printf("Hello, World!");
   return 0;
}
Output

Hello, World!


 

Comments

Post a Comment

Popular posts from this blog

C - character set, identifiers, keywords

C - Constants and Variables

C - Loops