Question discussion

What is the output of the following C++ program?#include using namespace std; void f(int) { cout

1706Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C++ program?

#include <iostream>
using namespace std;
void f(int) { cout << "I"; }
void f(double) { cout << "D"; }
int main() {
    f('a'); f(3.5f); f(2);
    return 0;
}
  • ADDI
  • BIID
  • CIDI
  • DIII
Correct answer: C

Explanation

The char is promoted to int, the float is promoted to double (a better match than converting to int), and the literal 2 is an int, giving I, D and I.

Discussion 0

Nobody has replied yet. Start the discussion!