C - Structure of C Program


Next >>

Every C program contains a number of building blocks which are known as functions. Each function can perform specific task.

    Include Header File Section

    Global Declaration Section

    /* Comments */

    main() /*Function name * /
        /* comments */

        Local Declaration Part

        Executable Part

    User-defined Function

Let's discuss about the various part of this structure.

Include Header File Section

  • All C program depends up some header file. These header file contain function definition that is used in our program.
  • The header files have a default extension with ".h ".
  • The header file is included in the program by using " #include " directive.

For example:

#include <stdio.h> or #include "stdio.h"
#include <conio.h>

Some of the header files are:

  • stdio.h---standard i/o functions
  • stdlib.h---defines library function
  • math.h---mathematical functions
  • string.h---string functions
  • time.h----time holding functions
  • conio.h-- console in/out, that means, the ways of getting data to and from the console devices (keyboard & screen). This is required if our program has clrscr( ) and getch( )

Global Declaration Section

  • Here declare some variables which are used in more than one function. These variables are called global variables.
  • This must be declared outside of all the function.

main () function

  • Every C program must contain main() function because this is an entry point of every program.
  • Program execution is always begin with main() function and then it starts from open brace( { ) and ends with close brace( } ).
  • Within ‘{ } ’, we will write an entire program.

Declaration Part

  • Here declare the entire variables which are used in executable part.
  • Variable initialization is done in this section, that means, providing initial value to the variables.
  • These variables are called local variables.

Executable Part

This contains statement which may be single statement or set of statements.

User-defined Function

  • The user is allowed to define their own function.
  • In general, this function can be defined after the main() function.
  • Sometime, this function may be defined before the main().
  • This part is not compulsory.


  • Comments are used to understand the flow of the program.
  • It is very useful for documentation.
  • Usually the comments are placed between the delimiters/*-------------*/
  • while execution, the compiler does not execute the comments.
  • The programmers wish to include the comments anywhere in their programs.

Rules for Program Writing

  • All statement should be written in lower case letters.
  • Upper case letters used for symbolic constants.
  • Blank space may be inserted between the words which improve the readability of the statement.
  • C program is usually case sensitive. For example, variable name "COUNT" is different from the variable name "count".
  • It is not necessary to fix the position of the statements in the program.
  • Each statement should be terminated with semicolon. For example d = a + b;
  • More than one statements have to be written in one line that are separated by using semicolon. For example
    printf(" the main program ");   d = a + b;
  • Opening and closing brace should be balanced.

<< Previous

Next >>