Structure of C Program by G Krishna Chauhan


Before the basic building blocks of the C programming , We Should know about C program structure so that we can take it as a reference in the upcoming chapters.


  • Documentation section: The documentation section consists of a set of comment lines giving the name of the program, the author and other details, which the programmer would like to use later.

  • C Preprocessor: The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. We'll refer to the C Preprocessor as CPP.

    All preprocessor commands begin with a hash symbol (#). It must be the first nonblank character, and for readability, a preprocessor directive should begin in the first column. The following section lists down all the important preprocessor directives.

  1. Link section: The link section provides instructions to the compiler to link functions from the system library such as using the #include directive.
  2. Definition section: The definition section defines all symbolic constants such using the #define directive.

  • Global declaration section: There are some variables that are used in more than one function. Such variables are called global variables and are declared in the global declaration section that is outside of all the functions. This section also declares all the user-defined functions.

  • main () function section: Main Function is responsible for execution of any Program. Every C program must have one main function section. This section contains two parts; declaration part and executable part

  1. Declaration part: The declaration part declares all the variables used in the executable part.
  2. Executable part: There is at least one statement in the executable part. These two parts must appear between the opening and closing braces. The program execution begins at the opening brace and ends at the closing brace. The closing brace of the main function is the logical end of the program. All statements in the declaration and executable part end with a semicolon.


  • Subprogram section: If the program is a multi-function program then the subprogram section contains all the user-defined functions that are called in the main () function. User-defined functions are generally placed immediately after the main () function, although they may appear in any order.

    A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function. A function declaration tells the compiler about a function name and how to call the function.A function definition in C programming consists of a function header and a function body.While creating a C function, you give a definition of what the function has to do. To use a function, you will have to call that function to perform the defined task.


All section, except the main () function section may be absent when they are not required.



No comments:

Post a Comment