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:
You can optionally watch the video illustrating Basic Structure of a C Program.
- 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.
- 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.
- 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.
- 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.
- 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.
- Declaration part: The declaration part declares all the variables used in the executable part.
- 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.
- 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.