☰ C Programming Language
Structure and First C Program


A C program is divided into six sections: Documentation, Link, Definition, Global Declaration, Main() Function, and Subprograms. While the main function is compulsory, the rest are optional in the structure of the C program.

  • Documentation Section
    • The documentation section is the part of the program where the programmer gives the details associated with the program. He usually gives the name of the program, the details of the author and other details like the time of coding and description. It gives anyone reading the code the overview of the code.
  • Link Section
    • All header files are included in this section which contains different functions from the libraries. A copy of these header files is inserted into your code before compilation.

      #include<stdio.h>

      #include<stdio.h> is a pre-processor command, which tells a C compiler to include stdio.h file before going to actual compilation.
  • Definition Section
    • Includes pre-processor directive, which contains symbolic constants. E.g.: #define allows us to use constants in our code. It replaces all the constants with its value in the code.
  • Global Declaration Section
    • Includes declaration of global variables, function declarations, static global variables, and functions.

      int d;
      int calsum(int x, int y, int z);

  • main() Function
    • For every C program, the execution starts from the main() function. It is mandatory to include a main() function in every C program.

      Each main function contains 2 parts. A declaration part and an Execution part. The declaration part is the part where all the variables are declared. The execution part begins with the curly brackets and ends with the curly close bracket. Both the declaration and execution part are inside the curly braces.

      void main()
      {
       int a, b, c;
       printf(“\n Enter three number”);
       scanf(“%d%d%d”, &a, &b, &c);
       printf(“\nSum = %d”, callsum(a, b, c));
      }

  • Sub Program Section
    • All the user-defined functions are defined in this section of the program.

      They can contain the inbuilt functions and the function definitions declared in the Global Declaration section. These are called in the sub function.

      int calsum(int x, int y, int z)
      {
       d = x+y+z;
       return(d);
      }





 Video Lecture

google Ads.