Structure of c program

Every C program contains a number of several building blocks known as functions. Each function of it performs task independently. A function is subroutine that may consist of one or more statements.


Include header file section
Global Declaration section

void main (void)  /*main function */
	Declaration part
	Executable part
user-defined functions

  • Include header file section

    • C program depends upon some header files for function definition that are used in a program. Each header file by default is extended with .h.
    • The file should be included using #include directive as given below.
    • Example:

      #include  or #include “stdio.h.”
  • Global declaration

    • This section declares some variables that are to be used in more than one function. These variables are known as global variables.
    • This section must be declared outside of all the functions.
  • Function main(void)

    • Program written in C language contains a void main(void) function. Arguments, if needed, are specified within the parentheses following the function name main.
    • Here in this program void enclosed within a bracket indicates that no arguments are passed to the main function. The keyword void before main returns nothing.
  • Declaration part

    • The declaration part declares the entire variables that are used in executable part.
    • The initialization of variables is also done in this section.
    • The initialization means providing initial value to the variables.
  • Executable part

    • This part contains the statements following the declaration of the variables. It also contains a set of statements or a single statement.
  • User-defined function

    • The functions defined by the user are called user-defined functions. These functions are generally defined after the main() function.
    • They can also be defined before main() function. This portion is not compulsory.
  • Comments

    • Comments are not necessary in the program. However, to understand the flow of programs, programmers can include comments in the program.
    • Comments should be placed between the delimiters /* and */. The compiler does not execute comments.