Structure of C Program with Example

In this post, you will learn the basic structure of the ‘C’ program with an example. 

Structure of the C Program

The basic structure of the ‘C’ program consists of

Documentation section

This section consists of a set of comment lines giving the name of the programmer, the name of the program, and other details, that the programmer would like to use later. It starts with ‘\*’ and ends with ‘*/’.

Link section

This section provides instructions to the compiler to link functions from a system library. It is as “#include<stdio.h>”.

Definition section

This section defines all the symbolic constants.

Global Declaration section

There are some variables that are used in more than one function, such variables are called global variables & are declared in the global declaration section.

main() function section

Every C program must have one ‘main’ function section. This section contains two parts i.e. declaration part and the executable part. 

Declaration part

The declaration part declares all the variables used in the executable part. These two parts must appear between the opening and closing braces {}.

Declaration & Execution Parts

The program execution begins at the opening brace and ends at the closing brace. All statements in the declaration and executable part end with a semicolon (;).

Sub Program functions

The sub-program functions contain all the user-defined functions that are called in the main function.
User-defined functions are generally placed immediately after the main function.

C Program Example

/**                     //Documentation
 * file: age.c
 * author: you
 * description: program to find our age.

#include <stdio.h>      //Link

#define BORN 2000       //Definition

int age(int current);   //Global Declaration

int main(void)          //Main() Function
  int current = 2021;
  printf("Age: %d", age(current));
  return 0;

int age(int current) {     //Subprograms
    return current - BORN;