Embercode
✕
C++ Functions and ScopeQuick quiz

Pure functions

6 questions. Covers Pure functions.

Questions 1 to 5 of 6

  1. 1. True or false: this function is pure. ``cpp int offset = 2; int shifted(int x) { return x + offset; } ``
  2. 2. True or false: this function is pure. ``cpp int next_ticket_pure(int counter) { return counter + 1; } ``
  3. 3. What does this program print? ``cpp #include <iostream> int offset = 2; int shifted(int x) { return x + offset; } int main() { std::cout << shifted(5) << ' '; offset = 4; std::cout << shifted(5) << ' ' << shifted(5) << '\n'; } ``
  4. 4. What does this program print? ``cpp #include <iostream> int next_ticket() { static int counter = 0; return ++counter; } int next_ticket_pure(int counter) { return counter + 1; } int main() { std::cout << next_ticket() << ' ' << next_ticket() << ' ' << next_ticket() << '\n'; std::cout << next_ticket_pure(7) << ' ' << next_ticket_pure(7) << '\n'; } ``
  5. 5. Which of these is hidden state, meaning an input the function uses that is not in its parameter list?

5 question(s) left on this page.