Question 3
Back to Exercise
What is the output of the following C++ program?
#include <iostream>
void f(int) { std::cout << 'I'; }
void f(double) { std::cout << 'D'; }
int main() {
f(5);
f(5.0);
f(5.0f);
f('5');
f(true);
f(5L * 1.0);
std::cout << '\n';
return 0;
}
- A IDDIID Correct
- B IDIIID
- C IDDDID
- D IDDIDD
Correct Answer: Option A
5 → int; 5.0 → double; float promotes to double; char and bool promote to int; 5L × 1.0 is a double.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!