Every C program has a definite structure that is based on the basic structure of the C language. A typical C program mainly consist of 6 main sections as follows:

  1. Documentation Section
  2. Link Section
  3. Definition Section
  4. Global Declaration Section
  5. main() Function Section
  6. Sub Program Section

Without the above components the C program may not execute or compile properly.

Overview of typical C program structure

Documentation Section
Link Section
Definition Section
Global Declaration Section

  Declaration part
  Executable part

Sub program Section
  Function_1 ()
  Function_2 ()
  Function_n ()

1. The Documentation Section

The Documentation Section consists of a set of comment lines giving the name of the program and other details. Documentation section helps anyone to get an overview of the program. Comments are ignored by compiler and are used to provide documentation to people who reads that code. It consists of two type of comment system namely Single line comment and Multiline comment.

  1. The single line comment is created by using two forward slashes //
  2. The multiline comment is created by using the combination /* */
//Single line comment


The link section consists of header files that are processed before the compilation of the program by the program called as preprocesser. We use a preprocesser directive command to link the header files. The preprocesser directives commands begins with the hash symbol #.


3. Definition Section

All the symbolic constants are defined in the Definition Section. A symbolic constant is a constant value that remains unchanged throughout the program execution. A definition section also consist of the preprocesser directive command.

#define PI 3.14

4. Global Declaration Section

In global declaration section, global variables and user defined functions are declared. The variable declared in this section can be accessed and used anywhere in the program.

int radius;

5. main() Function Section

The mandatory part of every C program is the main() Function section. We can’t omit this section. The execution of the C program starts from this section and also ends in this section. The main() Function section consists of two parts:

  1. Declaration part

The declaration part consists of all the variables and functions declaration that will be used in the executable part.

  1. Executable part

This part contains the statements that are to be executed by the compiler. There should be atleast one executable statement in this part.

int main()
  float rate;                     //Declaration part
  int sum;
  printf("Enter the rate: ");     //Executable part
  scanf("%f", &rate);
  printf("Enter the sum: ");
  scanf("%d", &sum);
  printf("The rate is : %f \n", rate);
  printf("The sum is : %d \n", sum);
  return 0;

The main() Function section must have opening and closing braces { }. Every statements inside main() function must be terminated with semicolon ; except for some exceptions.

6. Sub program section

Subprogram section is consists of all the user-defined functions. It is not compulsary to have the sub program section. A complete and fully functional C program can also be created by omitting this section. A sub program section generally occurs after the main() function section.

void example()
  printf("This is a sub program.");

A typical example of C program having all the sections

//A program to calculate area and perimeter of circle
#define PI 3.14            

float radius;             

int main()
    float area;
    void perimeter(void);
    printf("Enter the radius of the circle: ");
    area = PI*radius*radius;
    printf("Area is = %f ", area);
    return 0;

void perimeter()
    float per;
    per = 2*PI*radius;
    printf("\nPerimeter is = %f",per);