Embercode
✕
C++ Functions and ScopeQuick quiz

Callbacks

6 questions. Covers Callbacks and function pointers.

Questions 1 to 5 of 6

  1. 1. Match each callable type to what it can do.

    Choose the matching item for each row.

  2. 2. Match each error message to its cause.

    Choose the matching item for each row.

  3. 3. Predict the output of this program. ``cpp #include <iostream> using IntOp = int (*)(int); int apply_twice(IntOp op, int start) { return op(op(start)); } int main() { std::cout << apply_twice([](int n) { return n * n + 1; }, 2) << '\n'; } ``
  4. 4. Predict the output of this program. ``cpp #include <functional> #include <iostream> #include <vector> int main() { std::vector<std::function<int()>> jobs; int base = 3; jobs.push_back([base] { return base * 10; }); base = 7; jobs.push_back([&base] { return base * 10; }); std::cout << jobs[0]() << ' ' << jobs[1]() << '\n'; } ``
  5. 5. Which statement about std::function is correct?

5 question(s) left on this page.