DEV Community

Cover image for Structure of a C Program
Mukesh Kumar
Mukesh Kumar

Posted on

Structure of a C Program

“In the previous chapter, we learned what C language is and why it is important.
But now the real question is…

👉 How does a C program actually look?
👉 What are the parts inside it?...Read More

1. What is the Structure of a C Program?

“Every C program follows a specific format or structure.
Just like a house needs a proper design — foundation, walls, roof —
a C program also has essential parts.

Without structure, the program will not compile or run.”

A basic C program contains:

Documentation Section...Read More

2. Documentation Section

“This is the top part of the program.
It contains comments that explain the program.”

Example:

/* This program prints Hello World */

📌 Comments are not executed by the computer.
They are written only for humans to understand...Read More

3. Link Section

“This section tells the compiler to include header files.”

Example:

include

Here:

include is a preprocessor directive

stdio.h is a header file...Read More

4. Definition Section

“This section defines constants using #define.”

Example:

define PI 3.14

Here:

PI becomes a constant value...Read More

*5. Global Declaration Section
*

“In this section, variables and functions are declared before the main function.”

Example:

int a = 10;
float b = 5.5;

These variables can be accessed throughout...Read More

6. The main() Function (Most Important Part)

“This is the heart of every C program.”

Every C program must have a main() function.
Execution always starts from main().

Example:

int main() {
printf("Hello World");
return 0;
}

Let’s understand it:

int → return type

main() → starting point of program...Read More

7. User-Defined Functions

“These are additional functions created by the programmer.”

Example:

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

These functions help:

Divide program into small part...Read More

💻 Complete Basic Example Program

Now let us see the complete structure together:

/* Program to print Hello World */

include // Link Section

define PI 3.14 // Definition Section

int main() // Main Function
{
printf("Hello World...Read More

🔄 How a C Program Executes

Now understand the execution process:

Write the code

Compile the program (using compiler like GCC)

If no errors → executable file is created

Run the program

Output is displayed

📌 Compilation converts human-readable...Read More

🧠 Important Points to Remember

Every program must have main()

Statements end with semicolon ;

Curly braces {} define blocks

Header files are necessary for built-in ...Read More

*📌 Summary *

“In this chapter, we learned:

The complete structure of a C program

Different sections of a program

Importance of main() function

How execution flow works

Basic example of a C program...Read More

Top comments (0)