Question

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

Option 3 : Compilation error

Advertisement

Detailed Solution

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

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the result of compiling the following C++ program? template <typename T> T add(T a, T b) { return a + b; } int main() { cout << add(5, 2.5); } / निम्नलिखित C++ प्रोग्राम को कंपाइल करने का परिणाम क्या है?

1.
7
2.
7.5
3.
Compilation error
4.
6

Correct Answer: Compilation error

Template argument deduction requires both arguments to match the same type T, but here they are int and double, so no matching function exists and compilation fails. / टेम्पलेट आर्गुमेंट डिडक्शन के लिए दोनों आर्गुमेंट्स का एक ही प्रकार T से मेल खाना आवश्यक है, पर यहाँ वे int और double हैं, इसलिए कोई उपयुक्त फंक्शन नहीं मिलता और कंपाइलेशन विफल होता है।

Downloaded from PrepSnap (prepsnap.in)