← Quiz: Operators and Templates: all 10 questions
Quiz: Operators and Templates · Question 3 of 10
What does this print? (code)
What does this print?
#include <iostream>
using namespace std;
template <typename T>
T twice(T x) { return x + x; }
int main() {
cout << twice(21) << " " << twice(1.5);
return 0;
}
- A.2121 3
- B.42 3
- C.42 1.51.5
- D.Error
Answer & explanation
Correct answer: 42 3
The template is generated for int (42) and for double (3).
Can you get the rest right without peeking?
Take the timed Quiz: Operators and Templates quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →