Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 2 : Compile error

Advertisement

Detailed Solution

सही उत्तर Compile error है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following C++ code? template <typename T> T add(T a, T b) { return a + b; } int main() { std::cout << add(2, 3.5); return 0; } / निम्नलिखित C++ कोड का आउटपुट क्या है?

1.
5.5
2.
Compile error
3.
5
4.
Runtime error

Correct Answer: Compile error

Template argument deduction tries T=int from the first argument and T=double from the second; the conflict means no matching function is found, so the program fails to compile. / टेम्पलेट आर्गुमेंट निगमन में T=int और T=double का संघर्ष होता है, अतः कोई उपयुक्त फंक्शन नहीं मिलता और कंपाइल त्रुटि आती है।

Downloaded from PrepSnap (prepsnap.in)