Question 12
Back to Exercise
What is the output of the following program, compiled as C23?
#include <stdio.h>
int main(void) {
auto r = 3 > 2;
bool b = 3 > 2;
printf("%zu %zu %d\n", sizeof r, sizeof b, r + b);
return 0;
}
- A 4 1 2 Correct
- B 1 1 2
- C 4 4 2
- D 1 1 1
Correct Answer: Option A
Even in C23, a comparison yields an int, so auto deduces int (4 bytes). Stored in a bool it becomes 1 byte. In r + b both are ints with value 1.
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!