Skip to content

Module 1 — Self-Assessment

Six questions that require recall, and three that require reasoning. Answers state what a full-credit answer contains, not merely the right option — because in self-study, "I knew that" is not evidence of anything.


Part A — Recall and comprehension

1. Put these in order: linking, compilation, preprocessing. (Answer: preprocessing, compilation, linking.)

2. Which stage fails for a missing semicolon, and which for a missing function definition? (First: compilation. Second: linking — the declaration satisfied the compiler, and no definition was ever supplied.)

3. Why does std::cout need the std:: part? (The standard library's names live in the std namespace, so that thousands of names cannot collide with yours. cout is the one in std.)

4. Name the four pillars, and give one example of each from a system you choose. (Full credit requires an example that would stop working if the pillar were removed — not a phrase like "encapsulation is hiding data".)

5. What is the difference between a class and an object? (A class is a type — a description. An object is one instance of it, with its own data. Two objects of the same class share the code and own their own values.)

6. Name one thing a class protects that parallel arrays cannot, and one thing a class with all-public members does not protect. (First: the correctness of a relationship between fields. Second: anything at all — see Module 4.)


Part B — Prediction and explanation

These are the questions that matter. Anyone can recite that a by-value parameter is a copy; far fewer can say what the program prints.

7. Predict the output, and say why the two calls differ:

#include <iostream>
void addOne(int n)  { n = n + 1; }
void addOne(int& n) { n = n + 1; }
int main() {
    int count = 5;
    addOne(count);
    std::cout << count << '\n';
    addOne(count);
    std::cout << count << '\n';
}

Answer. 5 then 6.

Full credit: the first line prints 5 because addOne(int) received a copy and doubled the copy, which died when the function returned. The second call picks addOne(int&) — the reference overload — which is bound to count itself, so count becomes 6. Note that overload resolution chose between two functions with the same name; the argument's type decided which one ran. Full credit also notes that the first call could not have affected the caller whatever it did inside, because a non-reference parameter is always a separate object.

8. Predict whether this compiles, and if it does, what it prints:

#include <iostream>
#include <algorithm>
using namespace std;
int count = 0;
int main() {
    cout << count << '\n';
}

Answer. It does not compile: error: reference to 'count' is ambiguous.

Full credit: std::count and the global ::count are both visible unqualified, so the compiler cannot choose. Removing the using line fixes it. Full credit also notes that including <algorithm> is what made the collision appear — the program compiled fine before that line was added, which is what makes this a slow-acting mistake.

9. Predict which of these three programs fails, and at which stage:

// (a)
int main() { int n = 1  return 0; }

// (b)
#include <iostream>
double half(double value);            // declared
int main() { std::cout << half(4.0); }

// (c)
#include <iostream>
int main() { int* p = nullptr; std::cout << *p; }

Answer. (a) fails at compile time; (b) fails at link time; (c) compiles and links, and its behaviour when run is undefined.

Full credit: naming the stage for each, and for (c) explicitly saying that a run which appears to work proves nothing — the language makes no promise, so "it worked on my machine" is not evidence. Full credit would also note that (a)'s actual error will point at return, one line below the missing semicolon.


Marking yourself

Score What it means
≥ 80%, every miss explained Move on to Module 2
60–79% Re-read the sections behind the misses, then retake in a week
< 60% Redo Concepts and Lab 1 before going further

A quiz is diagnostic, not a grade. The useful output is the list of ideas that need another look — write that list down, because it is revision material no textbook can supply for you.

The explanation test. For any question you got wrong, explain the answer out loud to an imaginary classmate. If you reach a point where you say "…and then it just works", you have located the gap: it is that line, not the whole topic.


Re-test schedule

The re-test is what makes this work, and it is the step almost everyone skips. Come back to these three and answer them again without looking:

  • In a week: question 7 (the reference overload) — Module 2 needs it.
  • After Module 4: question 6 (what a class does not protect) — Module 4 answers it fully, and your answer should change shape entirely.
  • Before the capstone: question 4 (the four pillars) — by then you should be able to answer it with examples from code you wrote, not from memory.

Next: Summary — what to retain, and what to do before you move on.