Question

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

Option 2 : Compilation error — ambiguous call / कंपाइलेशन त्रुटि — अस्पष्ट कॉल

Advertisement

Detailed Solution

सही उत्तर Compilation error — ambiguous call / कंपाइलेशन त्रुटि — अस्पष्ट कॉल है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

Consider the C++ declarations `void f(int a, int b = 5);` and `void f(int a);`. What does the call `f(10);` do? / C++ घोषणाओं `void f(int a, int b = 5);` और `void f(int a);` पर विचार करें। कॉल `f(10);` क्या करेगा?

1.
Calls the first overload with b = 5 / पहले overload को b = 5 के साथ कॉल करता है
2.
Compilation error — ambiguous call / कंपाइलेशन त्रुटि — अस्पष्ट कॉल
3.
Calls the second overload / दूसरे overload को कॉल करता है
4.
Runtime error / रनटाइम त्रुटि

Correct Answer: Compilation error — ambiguous call / कंपाइलेशन त्रुटि — अस्पष्ट कॉल

Both overloads are viable for a single `int` argument and neither is better, so overload resolution fails with an ambiguity error at compile time. The trap is assuming the default argument or the exact-arity overload automatically wins. / एक `int` आर्गुमेंट के लिए दोनों overload उपयुक्त हैं और कोई बेहतर नहीं है, अतः overload resolution कंपाइल समय पर ambiguity त्रुटि देता है। जाल यह मानना है कि default argument या exact-arity वाला overload स्वतः जीत जाता है।

Downloaded from PrepSnap (prepsnap.in)