Structure of a C Program
💻 Structure of a C Program (Easy Explanation)
A C program follows a specific structure (format). Understanding this structure helps you write programs correctly 👍
🔹 Basic Structure of C Program
#include <stdio.h> // 1. Header files
int main() { // 2. Main function
printf("Hello, World!"); // 3. Statements (instructions)
return 0; // 4. Return statement
}
🔹 Explanation of Each Part
1. 📂 Header Files
#include <stdio.h>
- Used to include standard libraries
-
stdio.his used for input/output functions likeprintf()
2. 🔑 main() Function
int main()
- This is the starting point of every C program
- Execution begins from here
3. 🧾 Body of Program (Statements)
{
printf("Hello, World!");
}
- Contains instructions to perform tasks
-
Each statement ends with a semicolon
;
4. 🔚 Return Statement
return 0;
- Ends the program
-
0means program executed successfully
🔹 Optional Parts (Advanced)
📝 Comments
// This is a comment
/* Multi-line comment */
- Used to explain code
- Ignored by compiler
🔧 User-defined Functions
void myFunction() {
printf("Custom Function");
}
- Helps in code reusability
🔹 Flow of Execution ▶️
- Header files included
-
main()function starts - Statements execute one by one
-
Program ends with
return 0
🔹 Simple Analogy 🤔
Think of a C program like a recipe 🍲:
- Header files = Ingredients
- main() = Cooking start
- Statements = Steps
- return 0 = Dish ready
🔹 Summary 📝
A C program mainly has:
- Header files 📂
- main() function 🔑
- Statements 🧾
- Return statement 🔚
Comments
Post a Comment