Home » Structure of a ‘C’ Program

Structure of a ‘C’ Program

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

Documentation Section:

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.

Definition Section:

  • 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:

  1. declaration part
  2. 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.

Subprogram Section:

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.


Leave a comment

Your email address will not be published. Required fields are marked *

‘C’ Practical

  1. To get fomiliar with the structure of a ‘C’ program and print “Hello World!” on computer screen.
  2. To perform addition, subtraction, multiplication and division operations on two integers.
  3. To use unformatted 1/0 functions (getchar() and putchar(), gets() and puts()).
  4. To use scanf() function to read integers (%d, %i, %o, %u, %x), characters (%c), floating point numbers (%f, %g, %e), strings (%s, scanset).
  5. To use printf() function to format and print output (%d, %i, %o, %u, %x, %e, %E, %f, %g, %c, %p, %c, %s, %n)
  6. To change width, precision and alignment of the output of printf().
  7. To perform and, or, not, exor, left-shift and right-shift operations on integers.
  8. To check whether a given integer is even or odd (if … else statement).
  9. To write month name corresponding to a month number (switch … case).
  10. To check whether a given integer is prime using while loop.
  11. To reverse the digits of a given positive integer using while loop.
  12. To generate the multiplication table of a given integer using for loop.
  13. To generate first n terms of Fibonacci series using do-while loop.
  14. To compute factorial of a given integer using for loop.
  15. To compute sum of elements of a one dimensional integer array.
  16. To find the largest element in a one dimensional array.
  17. To perform matrix addition and matrix multiplication using 2-D arrays.
  18. To convert the alphabetic characters of a string to uppercase.
  19. To find the length of a string.
  20. To use Standard Library String Functions (strcat(), strrev(), strcp(), strcmp())
  21. Writing a function to find sum of two integers.
  22. Writing a function to swap value of two integers (call by reference).
  23. Writing a function to compute factorial of a given integer (using recursion).
  24. To read and print multiple data items (roll_no, name, branch, semester etc.) pertaining to an individual student.
  25. Demonstrating the use of union
  26. Demonstrating the use of address and dereferencing operators
  27. Performing pointer arithmetic to manipulate an array
  28. To read the contents from a file and display it on screen
  29. To read names and addresss of persons and write them into a file.
  30. Write a program to read the contents of two different files and write it into the third file.