Every ‘C’ program consists of one or more modules called functions. In ‘C’ program, there are many preprocessor directives available. These preprocessor directives are used according to user’s requirement. Each function should be use on e main() function, because without main function no one function can be compiled and executed properly. The program will always begins by main() function. Any other function can be defined after the main() function.
Basic Structure of C Program
This section consists of comment lines which include the name of programmer. Documentation section helps anyone to get an overview of the program.
Header Files/Preprocessor Directives:
This consists of the header files of the functions that are used in the program. It provides instructions to the compiler to link functions from the system library. These library are helpful for reducing the complexity of program. These header files and preprocessor directives always start with hash (#) sign.
- In this section, user can define the variables and constants according to their requirement.
- All the symbolic constants are written in definition section. Macros are known as symbolic constants.
Global Declaration Section:
The global variables that can be used anywhere in the program are declared in global declaration section. This section also declares the user defined functions.
main() Function Section:
It is necessary have one main() function section in every C program. This section contains two parts:
- declaration part
- executable part
The declaration part declares all the variables, constant’s to used in the program. Variables can be local or global. The Execution part execute the user define statement. Each statement should be syntatically correct otherwise error generate.
These two parts must be written in between the opening and closing braces. Each statement in the declaration and executable part must end with a semicolon (;). The execution of program starts at opening braces and ends at closing braces.
The subprogram section contains all the user defined functions that are used to perform a specific task. These user defined functions are called in the main() function.