Skip to content
KALANBLON
Show contents

Chapter 3 of 7 · 10 min

Quiz: functions and the standard library

Functions, references, std::map and algorithms: let's check that you know how to rely on the standard library. You need 70% correct answers.

Quiz

6 questions · pass mark: 70%

  1. 1.What does this program display?

    One answer

    void add(int& x) { x += 10; }
    
    int main() {
        int a = 5;
        add(a);
        std::cout << a;
    }
  2. 2.Which parameter should a function use to read a large std::vector<double> without changing it?

    One answer

  3. 3.What does this code display?

    One answer

    std::map<std::string, int> m = {{"b", 2}, {"a", 1}};
    for (const auto& [k, v] : m) {
        std::cout << k << v << " ";
    }
  4. 4.Fill in the blank to test whether the key is present without creating it (C++20).

    Complete the code

    if (stock.____("rice")) {
        // ...
    }
  5. 5.What does std::find(v.begin(), v.end(), 42) return if 42 isn't in v?

    One answer

  6. 6.Which overloads can coexist with int area(int side);? (several answers)

    Several answers possible

Your progress is saved on this device. Create a free account to keep your progress on all your devices.