Question
Option 2 : I / I
Detailed Solution
सही उत्तर I / I है।
Question:
What is the output of the following C++ code? `template<typename T> void f(T x){ cout<<"T"; } void f(int x){ cout<<"I"; } int main(){ f(5); }` / निम्नलिखित C++ कोड का आउटपुट क्या होगा? `template<typename T> void f(T x){ cout<<"T"; } void f(int x){ cout<<"I"; } int main(){ f(5); }`
Correct Answer: I / I
When a non-template overload and a template specialization match equally well, overload resolution prefers the non-template function, so `f(int)` is chosen and prints I. The trap is assuming the template is preferred or that the call is ambiguous. / जब non-template overload और template specialization समान रूप से मेल खाते हैं, तो overload resolution non-template function को प्राथमिकता देता है, अतः `f(int)` चुना जाता है और I छपता है। जाल यह मानना है कि template को प्राथमिकता मिलती है या कॉल अस्पष्ट है।