Drills
Drills: check yourself
Answer first yourself, and only then open the answer.
1. Which block: sequence, selection or repetition?
a) While the water hasn't boiled: wait a minute.
b) If it rains, take an umbrella.
c) Pour in water. Switch on the kettle.
Answer
a) repetition, b) selection, c) sequence.
2. What does this line print?
printf("A\tB\n\"C\"\\D\n");
Answer
A B
"C"\D
\t is a tab, \n a new line, \" a quote, \\ one \.
3. The code compiled, but the build ends like this. What do you fix?
undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
Answer
The program has no function main: most likely it says Main or mian. The error comes from the linker (ld), not the compiler, so it has no line number.
4. What does this line print?
printf("C:\new\\file.txt\n");
Answer
C:
ew\file.txt
The \n after C: is a new line, not part of the path. There is no error, which is why such a place is easy to miss.
5. Write as pseudocode: of two numbers a and b, print the bigger one.
One correct answer
1. Read a and b.
2. If a > b:
2.1. Print a.
Otherwise:
2.2. Print b.
Sequence (1, then 2) and selection (2). When a equals b, b is printed, and that is correct too.