ProgrammingHardMicrosoft/Amazon SDE MCQ · GATE CS

What is printed?

What is printed?
void f(int)    { cout << "i"; }
void f(char)   { cout << "c"; }
void f(double) { cout << "d"; }
int main() {
    char a = 'a'; short s = 1; float x = 1;
    f(a); f(s); f(x); f(a + a);
}
  1. A. cidi
  2. B. cddc
  3. C. cici
  4. D. cidc

Correct answer: A. cidi

f(a) is an exact match (c). short has no exact overload, and promotion to int beats conversion to char or double (i). float promotes to double (d). a + a has type int after integral promotion (i).

More OOP with C++ and Java questions

Exams that ask this topic