Structure of a C Program
Introduction to C
Structure of a C Program
Variables and Data Types
Input and Output
Operators in C
Decision Making
If Statement
if...else Statement
Nested if Statement
Nested if...else Statement
Switch Statement
Loops
For Loop
While Loop
Do While Loop
Loop Comparison
Arrays
Strings
Functions
Function Types
Library Functions
User-Defined Functions
Recursion Function
Pointers
Structures
File Handling
Common Mistakes
Ideas
Structure of a C Program
A basic C program is organized into logical sections: documentation, header inclusion, definitions,
global declarations, the main() function, and user-defined functions.
// Documentation: My first structured program #include <stdio.h> // Header inclusion #define PI 3.14 // Definitions int add(int a, int b); // Function Declaration int main() { int result = add(5, 3); printf("Sum = %d\n", result); return 0; } int add(int a, int b) { // User-defined function return a + b; }
Simplified Breakdown
- Header Files: These bring ready-made features (like
printf) into your program. - #define: Used to create constants (like
PI) that stay the same throughout the program. - Function Declarations: These act as a "heads-up" to the compiler that a specific function exists.
- The main() Function: The heart of the program; this is where execution starts.
- User-Defined Functions: These help divide complex work into small, reusable blocks.
Example
Executing...
❌ Error:
✅ Output:
// Click Run ▶ to execute
🏋️ Test Yourself With Exercises
Take our quiz on Structure of a C Program to test your knowledge.
Browse Quizzes »