🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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;
}
  1. A.2121 3
  2. B.42 3
  3. C.42 1.51.5
  4. 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 →