Embercode
✕
C++ Functions and ScopeQuick quiz

Generic functions

7 questions. Covers Generic functions.

Questions 1 to 5 of 7

  1. 1. What is wrong with this code? ``cpp #include <iostream> T square(T value) { return value * value; } int main() { std::cout << square(3) << '\n'; } ``
  2. 2. In the total template, why does the lesson write T sum{}; instead of T sum;?
  3. 3. What does this program print? ``cpp #include <iostream> #include <string> template <typename T> T twice(T value) { return value + value; } int main() { std::cout << twice(4) << ' ' << twice(1.5) << ' ' << twice(std::string("ab")) << '\n'; } ``
  4. 4. The call below does not compile. Why? ``cpp #include <iostream> template <typename T> T larger(T a, T b) { if (a < b) { return b; } return a; } int main() { std::cout << larger(1, 2.5) << '\n'; } ``
  5. 5. The unsigned integer type that the lesson uses for sizes and positions is std::___.

    Type your answer.

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.