Introduction
One of the first questions a beginner will ask when learning C programming is: “What is the structure of C program?” Knowing the structure of a c program is akin to understanding the alphabet before writing words. If you don’t know the structure, you don’t have the foundation to create “bigger” concepts like functions, loops, or data structures.
In this blog post, I will define the structure of the C program, explain the structure, provide you a outline of a C program with example, and compare the structure of a C program versus a C++ program. By the end, you will have the knowledge to write your first program!
🔑 Why Learn the Structure of a C Program?
C programming is known as the mother of all languages and its syntax has been implemented in C++, Java, and even Python. Understanding the basic structure of a C program will allow you to:

Understand how program execution flow works
Write code with no errors that compiles and runs smoothly.
Easily transition to understanding the structure of a C++ program and other languages.
🧩 Basic Structure of C Program
Every C program follows a standard structure. Here’s the general template of C program structure:
#include <stdio.h> // Preprocessor directive
// Function declaration
int add(int, int);
int main() {
// Variable declaration
int a, b, sum;
// Taking input
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
// Function call
sum = add(a, b);
// Display output
printf("Sum = %d\n", sum);
return 0; // Exit status
}
// Function definition
int add(int x, int y) {
return x + y;
}
📌 Components of C Program Structure
Let’s break down the structure of C program with example step by step:

1. Documentation Section
This includes comments to describe the purpose of the program.
// This program adds two numbers
2. Preprocessor Directives
Used to include header files. Example:
#include <stdio.h> // standard input-output functions
#include <math.h> // math functions like sqrt, pow
3. Global Declarations
Variables, constants, or function prototypes declared outside main().
4. main() Function
Every C program must have main(). This is where execution starts.
5. Variable Declarations
All variables should be declared before use. Example:
int a, b, result;
6. Executable Statements
These are instructions like input, processing, and output.
7. User-Defined Functions
Functions outside main() help in modular programming.
📖 Structure of C Program With Example
Here’s a real example of C program structure:
#include <stdio.h>
// Function declaration
int square(int n);
int main() {
int num, result;
printf("Enter a number: ");
scanf("%d", &num);
result = square(num); // Function call
printf("Square = %d\n", result);
return 0;
}
// Function definition
int square(int n) {
return n * n;
}
👉 In this program:
- #include <stdio.h> – allows input/output functions.
- Function declaration – tells compiler about square().
- main() – execution starts here.
- Function definition – contains actual logic.
This is the basic structure of a C program with example.
🔄 Structure of C++ Program vs Structure of C Program
Now that you understand C, let’s compare it with the structure of C++ program.
Example of C++ Program Structure
#include <iostream> // Input-output stream
using namespace std;
int main() {
int a, b, sum;
cout << "Enter two numbers: ";
cin >> a >> b;
sum = a + b;
cout << "Sum = " << sum << endl;
return 0;
}
Key Differences
- C uses #include <stdio.h> while C++ uses #include <iostream>.
- C uses printf / scanf while C++ uses cin / cout.
- C++ supports OOP concepts (classes, objects, inheritance) which expand the program structure.
📝 Execution Flow of a C Program
In conclusion, the order of execution in the basic structure of C program is:
- PreProcessor executes first.
- Compiler translates the source code to machine code.
- Execution begins with main().
- Function calls are executed according to the logic structure that returning to main function.
- Ends with return 0
📊 Quick Comparison: Structure of C vs C++ Program

| Feature | Structure of C Program | Structure of C++ Program |
| Header Files | <stdio.h> | <iostream> |
| Input/Output | printf, scanf | cout, cin |
| Programming Type | Procedural | Object-Oriented + Procedural |
| Main Function | int main() | int main() |
| Functions | Supported | Supported + Classes/Objects |
🌟 Final Thoughts
Learning the structure of C program is the starting point on the way of becoming a good programmer. Once you learn this template, you can easily write any C program, because the same concepts relate to the structure of C++ program – which contains additional and more powerful features, such as classes and objects.
👉 You should always keep in mind that:
- Understand the structure, do not memorize syntax.
- Practice with small programs such as add, factorial, or prime check.
- Compare C and C++ program structure
So now that you know the structure of C program with example in the previous sections, go ahead and modify that program and build your own logic.