Nearby lessons

6 of 72

C - Program Structure

Every C program — from a three-line greeting to an operating system kernel — follows the same skeleton: #include at the top, main() as the starting point, and the real work inside { }. This lesson builds that skeleton, runs your first program, explains why main() returns a value, and ends with a program that adds two numbers.

The Structure of a C Program

Every C program follows a simple structure. Learn this skeleton and every program fits into it:

In simple words: every C program has the same skeleton — #include <stdio.h> brings in ready-made tools, main() is where the program starts, and the real instructions live inside { }.
Part What it does
#include <stdio.h> Brings in ready-made functions (printf, scanf) from the stdio header file.
int main() The starting point of the program. Execution always begins here.
{ } The body of main() — all the actual instructions live here.
return 0; Tells the operating system the program finished successfully.
; Every statement in C ends with a semicolon.

The four parts inside main() are not compulsory, but they are the natural order of thinking.

Example01
Loading editor…

Your First C Program

printf(...) is the function that prints text on the screen. The \n inside the quotes means move to a new line.

Common Mistake: forgetting the semicolon after printf("Hello");. The compiler reports the error on the next line, which is confusing the first time you see it. If an error makes no sense, check the line above it.
Example02
Loading editor…

Adding Two Numbers

Notice %d — it is a format specifier that tells printf where to print the integer sum. We study format specifiers properly in the printf lesson.

In simple words: %d is a placeholder. printf sees %d, goes to the value sum, and prints it exactly in that place. Change the value, and the same printf line prints the new number.
Example03
Loading editor…
📝 Key Takeaways
  • Program structure: #include <stdio.h> → main() → body in { }.
  • main() is where execution always begins.
  • Every statement ends with a semicolon.
  • printf() prints output; %d is the format specifier for integers.
  • int main() is standard C; return 0; reports success to the operating system.
  • The four parts of main(): declaration, input, processing, output.

🧠 Test Your Knowledge

5 Questions
Progress: 0 / 5

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.