← Quiz: Operators and Templates: all 10 questions
Quiz: Operators and Templates · Question 8 of 10
What does this print? (code)
What does this print?
#include <iostream>
#include <string>
using namespace std;
template <typename T>
T biggest(T a, T b) { return a > b ? a : b; }
int main() {
cout << biggest(4, 9) << " " << biggest(2.5, 1.5) << " " << biggest<string>("pune", "agra") << "\n";
return 0;
}
- A.9 2.5 agra
- B.9 2 pune
- C.9 2.5 pune
- D.Compile error
Answer & explanation
Correct answer: 9 2.5 pune
The template is generated for int, double and string; "pune" > "agra" alphabetically.
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 →