How the test works
The test after topic 12 checks topics 7–12: modules, pointers and bits, strings, structs, files and dynamic memory. This lesson is practice in the same shape.
Two parts
- Questions. Short code: what it prints, why it doesn't compile, where the bug is. You answer on your own, without a compiler. There are twelve here, each with an answer and an explanation.
- Programs. Two small tasks in the
test/2/folder:words.candshopping.c. Autotests check them, like the homework.
How long the real test takes and what you may use will be announced by your lecturer. Practice has no time limit, but try to write both tasks within an hour and a half.
How to check the programs
The task descriptions and the exact output text are in steps 4 and 5 and in the test/2/tests/ files. Run the tests like this:
ctest --preset debug -L test2
In CLion: the All CTest configuration and ▶. Both files already have the #includes and main; while they are empty, the tests fail.
These tasks give no points: GitHub Actions builds them and runs them with ASan and UBSan, but "Points" doesn't count them. They are for checking yourself.
What is checked, same as in the homework
- the program builds without warnings (
-Wall -Wextra -Werror -pedantic -Wvla); - the output matches the expected text letter by letter;
- each part is a function with a contract and an
assert, andmainonly calls them; shopping.c:realloc,freeandfcloseare there,fscanfisn't, and GitHub CI finds no leak;- no
TODOis left.
If you get stuck, go back to the topic the question comes from: every answer says which topic it belongs to.