What will be printed out as a result of the following code execution (C++11)?
#include <iostream>

template<typename T1, typename T2>
auto func(T1 a, T2 b) -> decltype(a>b?b:a)
    return a>b?b:a;

int main()
    int a = 3;
    double b = 5;
    std::cout << func(a,b)/2;
    return 0;
The ternary operator, depending on the truth of the condition, returns one of the two specified values, the type of which must match (by the definition of the operator). In this case, the ternary operator will cast both values to double. That is, the return value will be of type double, regardless of the value of the condition in the ternary operator.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Sign Up Now
or Subscribe for future quizzes