ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
void f(int)    { cout << "int "; }
void f(double) { cout << "double "; }
int main() {
    f('a');
    f(2.5f);
}
  1. A. double double
  2. B. int double
  3. C. int int
  4. D. Compilation error: ambiguous call

Correct answer: B. int double

char to int is an integral promotion, which beats the char-to-double conversion, so f('a') picks f(int). float to double is a floating-point promotion, which beats float-to-int, so f(2.5f) picks f(double).

More OOP with C++ and Java questions

Exams that ask this topic