Theory
Anatomy class begins
You have seen the marks program compile and run. Today you dissect it.
Every C program you will ever read, five lines or five lakh lines, has the same skeleton: something on top, one special function where execution begins, braces marking territory, and semicolons everywhere.
Learn the skeleton once and no C code will ever look alien again. Miss one semicolon and the compiler will lecture you, which is also today's lesson.
Practical
marks.c, dissected
/* The marks program: day two */
#include <stdio.h>
int main() {
printf("Riya\n");
printf("Marks: 78\n");
return 0;
}This example runs in Gri-Learn on the web, where you can edit it and see the output.
Theory
Line by line, top to bottom
/* ... */is a comment: notes for humans, invisible to the compiler (//comments a single line).#include <stdio.h>is a preprocessor directive: before compiling, it pulls in the standard input/output declarations, that is what makesprintfknown.int main()is the entry point: execution starts at main's first statement, always, wherever main sits in the file. Exactly one main per program.{ }braces mark main's block, its territory.- Each statement ends with a semicolon: the full stop of C.
return 0;tells the operating system: finished successfully.
Theory
A wedding invitation card
Think of the skeleton like a wedding card. The header at the top names the venue services (#include: what facilities this program will use). The card body has one main event section (main()), with a clear opening and closing ({ }). Every instruction inside is one line ending with a full stop (;). And the card ends with a formal closing line (return 0). Different weddings, same card format, always.
Think first
Predict the output
Read the dissected program above once more. What EXACTLY does it print, and on how many lines? (Remember \n from your keyboard-and-codes days.)
Show the answer
Two lines:
Riya
Marks: 78
Each \n is the newline character: it ends the current line. Without the first \n, both texts would crowd onto one line as RiyaMarks: 78. Predict-the-output questions live on such details, and \n is their favourite.
Quiz
A C program file contains three functions, and main() is written LAST in the file. Where does execution start?
- At main(), regardless of where it sits in the file
- At the first function written in the file
- At the #include line
- The program will not compile with main last
Show the answer
At main(), regardless of where it sits in the file
main() is the contractual entry point: the OS hands control to it no matter its position in the file. File order is for humans; execution order starts at main. And #include is processed before compilation, it is not "run". Programs with main written last compile and run perfectly.
Watch out
The three classic beginner errors
Missing semicolon: the compiler often complains about the NEXT line, so when an error points at line 6, check line 5 first. Case slips: C is case-sensitive, Main, Printf and PRINTF are strangers to the compiler. Brace mismatch: every { needs its }; one missing brace can produce a page of confused errors. All three are compile-time errors: the pipeline stops at the compiler, no .exe is born.
Formula
Exam recipe: "explain the structure of a C program"
Write the skeleton, then one line each: documentation section (comments), preprocessor directives (#include), main() function as the single entry point, declarations and statements inside { } each ending with a semicolon, return 0 to close. Add the marks program as your example. Skeleton + six labelled lines + example = full marks, every time.
Theory
What the skeleton is waiting for
Notice the program prints a fixed 78: change the marks and you must edit and recompile. Real programs hold values in variables, boxes with names, which is exactly the next lesson (character set, variables, constants). The skeleton stays; the muscles arrive one topic at a time.
Summary
Key takeaways
- Every C program: comments, #include directives, one main(), statements in { }, return 0.
- Execution always starts at main(), wherever it sits in the file.
- Every statement ends with a semicolon; a missing one flags the next line.
- C is case-sensitive: main, not Main.
- #include <stdio.h> makes printf known before compilation.
- Memory hook: the wedding card format, header, one main event, full stops.