Structure of the C Program

Last Updated : 2 Sep, 2026

The structure of a C program defines how its components are organized to make the code easier to read, understand, and maintain.

  • A C program commonly contains preprocessor directives, declarations, the main() function, and user-defined functions.
  • These components are organized according to the requirements of the program rather than a mandatory fixed order.
  • A well-structured program makes development, debugging, and maintenance easier.

Sections of the C Program

There are 6 basic sections responsible for the proper execution of a program. Sections are mentioned below:

1. Documentation

The documentation section describes the purpose and other relevant details of the program using comments.

  • It may include the program name, description, author, or creation date and time.
  • Comments are ignored by the compiler and do not affect program execution.
  • It provides an overview of the program and improves readability.

// description, name of the program, programmer name, date, time etc.

or

/*
description, name of the program, programmer name, date, time etc.
*/

2. Preprocessor Section

All the header files of the program will be declared in the preprocessor section of the program. Header files help us to access other's improved code into our code. A copy of these multiple files is inserted into our program before the process of compilation. 

#include<stdio.h>
#include<math.h>

3. Definition

Preprocessors process source code before compilation. Preprocessor directives begin with #. The #define directive is used to define constants or macros, which are replaced with their corresponding values or code during preprocessing.

#define long long ll

4. Global Declaration

The global declaration section contains global variables, function declaration, and static variables. Variables and functions which are declared in this scope can be used anywhere in the program. 

int num = 18;

5. Main() Function

Every C program must have a main() function, which serves as the entry point of the program. Declarations and executable statements are written inside its curly braces {}. The main() function typically returns an integer using int main(), where return 0 indicates successful program execution.

void main()

or

int main()

6. User-Defined Functions

User-defined functions are called in this section of the program. The control of the program is shifted to the called function whenever they are called from the main or outside the main() function. These are specified as per the requirements of the programmer. 

int sum(int x, int y)
{
return x+y;
}

Example: Structure of a C Program

C
// Documentation
/**                     
 * file: sum.c
 * author: you
 * description: program to find sum.
 */

// Link
#include <stdio.h>      

// Definition
#define X 20 

// Global Declaration
int sum(int y);   

// Main() Function
int main(void)       
{
  int y = 55;
  printf("Sum: %d", sum(y));
  return 0;
}

// Subprogram
int sum(int y) 
{
  return y + X;
}

Output
Sum: 75

Explanation

This program demonstrates the basic structure of a C program by calculating the sum of a number and a predefined constant.

  • #include <stdio.h> includes the standard input-output library for using printf().
  • #define X 20 defines X as a constant with the value 20.
  • int sum(int y); declares the user-defined sum() function before main().
  • The main() function initializes y with 55 and calls sum(y) to calculate the result.
  • The sum() function returns y + X, which gives 55 + 20 = 75.
  • printf() displays the result as Sum: 75.

Steps Involved in Compilation and Execution of a C Program

The following steps are involved in compiling and executing a C program:

  • Program Creation: Write the source code in a C source file.
  • Compilation: Compile the source code to check for errors and generate executable code.
  • Execution: Run the compiled program.
  • Output: View the result produced by the program.
Comment