Theory
The line you have typed ten times
Every program so far began with #include <stdio.h>, typed on faith.
Today, an experiment: delete that line and compile. The compiler instantly protests: "printf undeclared". Restore the line, peace returns.
So the whole power of printf somehow arrives through that one line. Where from, what exactly arrives, and who processes lines starting with #? Meet the preprocessor, the worker who edits your code before the compiler ever reads it.
Theory
Toolboxes and the wall of rules
A mechanic does not forge a spanner for every job; he says "bring the toolbox". #include <stdio.h> is exactly that sentence: bring the standard input/output toolbox, so printf and scanf are on the table. And #define is the workshop's wall-painted rule ("PASS_MARKS means 35"): painted once, and every worker reads the wall instead of memorising numbers.
Theory
Header files, formally
A header file (.h) holds declarations of ready-made functions, the compiler's introduction card for them.
- stdio.h (STanDard Input/Output):
printf,scanfand family. Standard everywhere. - conio.h (CONsole I/O):
getch()(wait for a keypress),clrscr()(clear screen). A Turbo C era, non-standard header: GCC and modern compilers do not ship it, and exams expect you to know that asterisk.
#include literally pastes the header's contents into your file before compilation. That is how printf becomes known.
Theory
The preprocessor and #define
The preprocessor runs BEFORE the compiler. Its directives start with # and take no semicolon, they are instructions about the text, not statements.
#define PASS_MARKS 35 creates a macro constant: before compiling, every PASS_MARKS in the code is textually replaced by 35.
Why bother? A bare 35 scattered through code is a magic number: unexplained and dangerous to change. A named constant explains itself, and when the university changes passing to 40, you edit ONE line.
Practical
The marks program, with its own rulebook
#include <stdio.h>
#define PASS_MARKS 35
#define MAX_MARKS 100
int main() {
int marks = 78;
float percentage = (marks * 100.0) / MAX_MARKS;
char result = (marks >= PASS_MARKS) ? 'P' : 'F';
printf("Percentage: %f, Result: %c\n", percentage, result);
return 0;
}This example runs in Gri-Learn on the web, where you can edit it and see the output.
Quiz
What happens if you delete #include <stdio.h> from the program above and compile?
- The compiler stops: printf is undeclared
- It compiles fine but prints nothing
- Only scanf stops working, printf survives
- Nothing changes, stdio.h is optional decoration
Show the answer
The compiler stops: printf is undeclared
stdio.h carries printf's declaration, its introduction card. Without it the compiler meets printf as a stranger and halts with "undeclared" (or implicit-declaration warnings on older setups). The header is not decoration; it is how ready-made functions become usable. The same fate awaits scanf, both live in stdio.h.
Think first
Spot the sneaky bug
A student writes: #define PASS_MARKS 35; (note the semicolon) and later if (marks >= PASS_MARKS). The compiler shows a confusing error on the if line. Think like the preprocessor: what did the if line become?
Show the answer
The preprocessor replaces textually, semicolon included: the line becomes if (marks >= 35;), and THAT is illegal. The error appears far from the real mistake, which is what makes it cruel. Rule: directives take no semicolon, because they are text-editing instructions, not C statements. This exact bug is a beloved spot-the-error exam question.
Watch out
Where marks leak
Adding semicolons to #include or #define (the bug above). Calling conio.h standard: it is Turbo C specific; say "non-standard" and collect the mark. Writing that #include "loads the function's code": it pastes declarations; the actual code arrives at LINKING (remember the pipeline: that is why printf's body lived in the library, not your .obj).
Theory
The unit so far, assembled
Look at today's code block: pipeline, structure, variables, identifiers, types, operators and directives, every lesson of this unit is in those ten lines. What the program still cannot do is ASK anything: marks are hard-coded. The next two lessons hand it ears and a mouth: scanf and printf, C's input and output statements.
Summary
Key takeaways
- Header files hold declarations of ready-made functions; #include pastes them in.
- stdio.h: printf/scanf (standard). conio.h: getch/clrscr (Turbo C, non-standard).
- The preprocessor runs before the compiler; directives start with # and take NO semicolon.
- #define NAME value replaces text before compiling: named constants, no magic numbers.
- One #define edit updates the whole program (PASS_MARKS 35 → 40).
- Declarations come from headers; function bodies arrive at linking.
- Memory hook: toolboxes (#include) and the wall of rules (#define).