Embercode
✕
Pointers and Memory AddressesQuick quiz

Stack and const

7 questions. Covers const and final.

Questions 1 to 5 of 7

  1. 1. A recursive function sum_to(n) makes n nested calls before it returns, and each call keeps its frame on the call stack until it returns. In Big-O terms, how much stack does one call to sum_to(n) use?
  2. 2. The function count_on_stack, with a 100 KB local array in each call, crashed at 83 levels, while count_on_heap reached about 87,000 levels. What explains the difference?
  3. 3. Which statement about int* const q = &x; is true?
  4. 4. The compiler rejects this class. What does it report, and why? ``cpp class Counter { public: int value() const { ++count_; return count_; } private: int count_ = 0; }; ``
  5. 5. What is wrong with this recursive function, and what does -Wall report? ``cpp #include <cstdio> int countdown(int n) { std::printf("%d\n", n); return countdown(n - 1); } ``

5 question(s) left on this page.