Structure of c programming language




Structure of a “C” Program

Documentation section 

Any additional information about the program in the form of comments. 

// This is single line comment

/*
This is 
multi line
comment 
*/

Link section 

Statement to link your code with external files like header files . 

#include <stdio.h>

Definition section

 Definition of user defined functions to be implemented . 

#define PI 3.14

Global declaration section 

Contains the declarations of global variables ,user defined data types etc . 

Main() section 

Execution of a C program begins at the main() function .Every program must contain one function that has its name as main().

main() 
{
    ... .. ...
    ... .. ...
}

Subprogram section

this section contains the definition of all user defined function.

Out of all these 6 section , link sections and main() function section are mandatory , rest 4 sections are optional and depends on the programmer whether to keep them in program or not . IT is a good practice to have a documentation section in your programs.


Example 1:- Sum of Two numbers.

#include <stdio.h>       

#include<conio.h>

void main()

{
  int a, b, c;

  printf("Enter two numbers");
  scanf("%d%d", &a, &b);

  c = a + b;

  printf("Sum of the numbers = %d\n", c);

  getch ();

}

Output :

enter two number - 10,2

sum of the number : 12

Output - 10,2

sum of the number : 12

  • Link section :-  In the above example we have included or we have linked the  header file <studio.h> that means we have linked our program from the external file this at the beginning of the programme . This is called link section. 

  • Declaration section :- Declaration section is of two types 1 is of global declaration section and another is of Deceleration section.

  • Global declaration section :- Global declaration section is  the part of program where we declare the global variable. Means the variable which will be declared once and will be used through the program. If we take specifically about variables then they are called global variables.

  • Local declaration section :- This is the section where we declare the variables which will work inside the main() function. If we take specifically about variables then they are called local variables .

  • main section :- Execution of a program starts actually from here . Every program must contain one function one function that has its name as main().

                HERE in this programining example we have used the main() function as void main() which simplifies that ths program will of return and value or any numerical value.


  • sub program section :- After the task to be done inside the main that we have already done in the above program so after the main function if we want to use our programming concept with USER DEFINED FUCTIONS the this section of programming comes into play.