web analytics

Write down the basic structure of a C program

Basic Structure of a C Program: 

Basic structure of a C program contains usage of all of its parts for at least once. Basic structure of a C program is different than a minimal C Program or an executable C program. A minimal C program which can be executed requires nothing but definition of its main() function, even if this function has no executable instruction, the C program would be executed successfully. However a basic structure of a C program would contain all of its parts. This is mainly for representing the structure of a C program. To write a C program, we first create functions and then put them together. A C program may contain one or more sections.

You Might Be Looking For This:

Explain the Basic Structure of a C Program with an Example.



You can optionally watch the video illustrating Basic Structure of a C Program.




Write down the basic structure of C programming.

  1. 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. These information give the program an identity and basic authority.
  2. Link section: The link section provides instruction to the compiler to link or include the required in-built functions from the system library such as using the #include directive. This is important, because if we need to use any in-built system function we must first include the library in which the function has been defined.
  3. Definition section: The definition section defines all symbolic constants using the #define directive. Having the constants being defined here, we can use them elsewhere in code.
  4. Global declaration section: There are some variables that are used in more than one function; these variables are called global variables and are declared in this global declaration section which is outside the definition of any function This section also declares all the user-defined functions. As this global scope, these functions and variables can be used from definition of other functions.
  5. main () function section: A C program must have one main function section in its structure. This section contains two parts; declaration part and executable part. However, the content of these two parts can be mixed.
    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 of the main function. 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.
  6. Subprogram section: If the program is a multi-function program then the subprogram section contains definition of all the user-defined functions which were declared earlier in the Definition Section. User-defined functions are generally placed immediately after the main () function, although they may appear in any order.

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

Thank you. Take a moment to share 🙏