Embercode
✕
C++ Functions and ScopeQuick quiz

Static and lambdas

8 questions. Covers Lambdas.

Questions 1 to 5 of 8

  1. 1. What does this program print? ``cpp #include <algorithm> #include <iostream> #include <vector> int main() { std::vector<int> v{59, 60, 61, 100, 0}; int n = std::count_if(v.begin(), v.end(), [](int s) { return s >= 60; }); std::cout << n << '\n'; } ``
  2. 2. What does this program print? ``cpp #include <iostream> int main() { int n = 10; auto f = [n](int k) mutable { n += k; return n; }; f(1); std::cout << f(2) << ' ' << n << '\n'; } ``
  3. 3. What does this program print? ``cpp #include <iostream> class Account { public: inline static int opened = 0; explicit Account(int cents) : cents_(cents) { ++opened; } static Account withBonus(int cents) { return Account(cents + 500); } int cents() const { return cents_; } private: int cents_; }; int main() { Account a(100); Account b = Account::withBonus(250); std::cout << b.cents() << ' ' << Account::opened << '\n'; } ``
  4. 4. What does the static keyword mean on a member function such as static Account withBonus(int cents)?
  5. 5. In auto addToTotal = [&total](int n) { total += n; };, what does &total mean?

5 question(s) left on this page.