Weekly Quiz number: 24 (2026)

Solve the quiz and collect tokens!

Type your nickname in the field below before submitting your solution. If you select the correct answer and submit it with your nick-name a token will be generated for you. Collect tokens and the corresponding nickname(s). If you get at least 10 of them you might be rewarded ;-)


Coding Quiz: Return Values

The C++ standard library is full of functions that do their job perfectly well and then hand you back a result you cannot afford to ignore. Discard it and the work is either incomplete or its outcome is unknowable. This quiz covers two classic cases where a discarded return value leads to silent misbehaviour.

Question 1: What is the state of v after this call to std::remove?

A developer wants to remove all zeros from a vector. After the call on line 6, what is the state of v?

int main() {
    std::vector<int> v = {0, 1, 0, 2, 0, 3};
    std::remove(v.begin(), v.end(), 0);
    // What is v here?
    return 0;
}
v contains {1, 2, 3} - the zeros have been erased
v still has size 6; the non-zero elements are shifted to the front, but the tail elements are unspecified

Question 2: The silent failure of std::remove

The code below attempts to delete a file by calling std::remove from <cstdio> and discards the return value. If the deletion fails (for example, because the file is read-only), what happens?

int main() {
    std::remove("precious_data.txt"); // return value discarded
    // caller assumes the file is gone
    return 0;
}
The program throws a std::runtime_error to report that the file could not be deleted
The failure is silently ignored; no exception is thrown and the program continues as if the file were gone

Make sure your nickname contains at least 8 characters and is a unique as possible.




Disclaimer: