Chapter 1 Summary and Quiz
Recap of the compile-and-run pipeline, program anatomy, and first programs.
What You Can Do Now
Three lessons ago a C program was a wall of punctuation. Now you can read every character of one, explain what each of the four pipeline stages did to it, and write the program that opens most C exams from an empty file. Before the quiz, walk the chapter once more at speed.
The Pipeline
Source code is text; the processor runs machine code; four tools bridge the gap, in order:
- The preprocessor handles
#lines: it pastes#included headers into your file and strips comments. - The compiler translates the expanded C into assembly, enforcing the language's rules. Syntax and type errors are reported here, sometimes one line after the real mistake.
- The assembler converts the assembly to machine code in an object file.
- The linker joins your object file with the standard library, resolving names like
printfto real code. "Undefined reference" errors are its voice.
The executable is a separate artifact: deleting the source does not affect it, and editing the source changes nothing until you recompile.
Only those stages can catch a mistake for you, and only certain mistakes. Syntax and type errors stop the compiler, and undefined references stop the linker, but a logic error (valid C that computes the wrong thing) and a data error (a correct program handed input it cannot cope with) both survive to run time, because no tool knows what you meant. Those you find by running the program and checking the answer.
Where It Came From
BCPL (Martin Richards, 1967) gave way to Ken Thompson's B (1970), and in 1972 Dennis Ritchie turned B into C at Bell Laboratories by adding the data types B lacked. Unix was rewritten in it soon after. Kernighan and Ritchie's 1978 book served as the language's only specification for years, which is why that dialect is called K&R C; vendor extensions then pulled it apart, and ANSI standardized it in December 1989 as C89. C spread because it is portable, structured, efficient, and extensible, with a deliberately small core of 32 keywords and a large standard library reached through #include.
The Dialect
This course compiles with gcc -std=c89 -pedantic-errors -Wall -Wextra, pinning the language to ANSI C, the dialect of university syllabi. The habits that follow:
- Comments are
/* ... */; the//form is C99 and a hard error here. - All declarations in a block come before the first statement.
mainis writtenint main(void)and ends with an explicitreturn 0;. In ANSI C, falling off the end ofmainhands the operating system an indeterminate status; the automatic 0 arrived only with C99.void main()was never standard.
The Skeleton and the Tools
Every program so far is: comment block, #include <stdio.h>, int main(void), statements in braces, return 0;. Exam papers name six sections in a fixed order, documentation, link, definition, global declaration, main, and subprogram, of which only main is compulsory; the three you have not met yet arrive in chapters 2 and 9.
Layout inside that skeleton is yours. C is free-form: whitespace between tokens carries no meaning, so several statements may legally share a line and your indentation is for human readers rather than the compiler. Whitespace inside a token is not allowed. Comments run /* ... */ and do not nest, so the first */ ends the comment whatever came before it.
Inside the skeleton you have three tools:
printf prints exactly the characters you give it. \n ends a line, \t is a tab, \" a literal quote, and %.2f renders a double with two decimal places. No newline is ever added for you.
Variables are named patches of memory: type then name, initialized at declaration, because reading an uninitialized variable is undefined behaviour. = stores the right side into the left, replacing the old value. Several names of one type may share a declaration, comma-separated, but each initializer binds to a single name, so double a = 0.0, b; leaves b uninitialized.
scanf delivers typed input into variables. It needs each variable's address, written &years, so it knows where to store what it reads. The specifier pairs matter: %d reads an int; %lf reads a double that printf prints with %f.
The Program to Rebuild From Memory
If you can write this without looking, the chapter is yours:
Run it and type something like 5000 7.5 3. Then take the quiz.
Looking Ahead
Chapter 2 opens the toolbox of types: what int, char, float, and double actually are, how big they are on different machines (and why exam papers sometimes assume sizes your laptop disagrees with), and every way C lets you write a constant.
How did you find this lesson?
Your rating helps us improve the content.
Create an account to track your progress and access interactive exercises. Already have one? Sign in.
Chapter 1 Summary and Quiz - Quiz
Test your understanding of the lesson.
Lesson Discussion
Share your thoughts and questions
No comments yet. Be the first to share your thoughts!