Question 13
Back to Exercise
What is the output of the following C++ program?
#include <iostream>
auto half(int x) { return x / 2; }
auto halfd(int x) { return x / 2.0; }
auto twice(char c) { return c + c; }
int main() {
std::cout << half(7) << ' ' << halfd(7) << ' ' << twice('a') << ' '
<< sizeof(half(7)) << sizeof(halfd(7)) << sizeof(twice('a')) << '\n';
return 0;
}
- A 3 3.5 194 484 Correct
- B 3.5 3.5 194 884
- C 3 3.5 aa 481
- D 3 3.5 194 444
Correct Answer: Option A
x / 2 is int, x / 2.0 is double, and char + char is promoted to int (97 + 97 = 194). Their sizes are 4, 8 and 4.
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!