Anatomy of a Program (and Its Output)
Statements, braces, escape sequences, and printing several lines โ plus the exact output rules printf follows.
Statements and braces
A statement is one instruction, ended with a semicolon. Braces { } group
statements into a block โ the body of main is a block. C does not care about
indentation, but humans do: always indent one level inside braces.
Printing exactly
printf prints its format string literally, except for escape sequences
and format specifiers. The escapes you need now:
| Sequence | Meaning |
|---|---|
| \n | newline |
| \t | tab |
| \" | a literal " |
| \\ | a literal \ |
Two printf calls with no \n run together on one line. The newline goes
where you put it โ this program prints AB then stops:
printf("A");
printf("B\n");
Multiple lines
printf("Line one\n");
printf("Line two\n");
printf("\n"); // an empty line
printf("The end.\n");
Output:
Line one
Line two
The end.
Exactness matters: in graded exercises, a missing space or newline is a wrong answer. Read the required output character by character.