Every C program follows a specific structure. Once you learn it, you will see it in every C file you ever read. It is like the skeleton of a building โ the same frame, just different rooms.
The #include Directive
At the top of almost every C program, you will see #include. This is a preprocessor directive. It tells the compiler to grab a header file and include its contents in your program.
Think of header files as toolboxes. <stdio.h> is the standard input/output toolbox. It gives you printf, scanf, and other functions for reading and writing data. Without it, you cannot print anything.
The main Function
Every C program needs a main function. This is where execution begins. When you run your program, the operating system looks for main and starts running the code inside it.
The int before main means the function returns an integer. The return 0; at the end tells the operating system the program ran successfully. A non-zero return means something went wrong.
Statements and Semicolons
Each instruction in C is called a statement. Every statement ends with a semicolon. Forget the semicolon, and the compiler will yell at you. This is one of the first mistakes beginners make, and it is totally normal.
Curly braces { } group statements together. They define the body of a function, a loop, or a conditional block. Always match your opening brace with a closing brace.
#include
int main() {
printf("This is a statement.\n");
printf("This is another statement.\n");
return 0;
}
Try it Yourself โ