C Program Structure

C programming language has a predefined program structure. These structure are divided into different sections, which helps to make c code more readable and easier to maintain. Some section in c program structure are optional but some are mandatory. The program structure sections are as follows.

  1. Documentation section
  2. Preprocessor section (Link)
  3. Definition section
  4. Global declaration
  5. Main function
  6. User defined functions (Subprograms)

Documentation section

This is the first section and always comes at the beginning or top of c program structure, which is used to provide information about c program.

  1. Name of Program
  2. Date
  3. Purpose or description of Program
  4. Developer name

This Documentation section is created using multiline comments.

/*
   Name of Program: Calculator
   Date: 06-02-2025
   Description: Basic Mathematical operations
   Developer name: XYZ
*/

This section is optional, but it is a good practice to add documentation in c program.

Preprocessor section

This section is used to include c header files which is further used by c program. It is also called link section. This preprocessor section comes after documentation section.

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

Definition section

This section of c program structure is used for #define symbolic constants. #define is also called macros. This Definition section comes after preprocessor section.

#define PI 3.14

Global Declaration

This global declaration section in a c program structure, contains all global variables and functions which are accessible in the entire c program. This is generally declared outside of or above main() function. This Global Declaration section comes after Definition section.

// Global Declaration of variable and function
int age;  
float speed;

void add(int no1, int no2);

main(){

}

main() function

This is the entry point of c program from where executions of program begins. Here all operations, function calling are performed. This main() function section comes after Global Declaration section.

void main(){
  int a = 50;
}

User defined functions or Subprograms

These are function definition, which contains set of statements, which executes whenever function is called. It helps in dividing c program into subprograms and increase code readability. This User defined functions section comes after main() section.

C Program structure Example

// Documentation Section
/*
   Name of Program: Calculator
   Date: 06-02-2025
   Description: Basic Mathematical operations
   Developer name: XYZ
*/
//Preprocessor section (Link)
#include<stdio.h>
#include<conio.h>

//Definition section
#define PI 3.14

//Global Declaration section
int age = 30;
void sayHello();

// main function section
void main(){

  printf("age is %d", age);
  sayHello();
}

// User defined functions(Subprograms) section
void sayHello(){
 printf("Hello");
}