Question 10
Back to Exercise
What is the output of the following C program on 64-bit Linux or macOS?
#include <stdbool.h>
#include <stdio.h>
int main(void) {
bool b = 5;
bool c = 0.1;
printf("%d %d %d\n", b, c, b + c);
return 0;
}
- A 5 0 5
- B 1 0 1
- C 1 1 2 Correct
- D 5 1 6
Correct Answer: Option C
Converting any non-zero value to bool gives 1 (true) – even 0.1, which an int conversion would turn into 0. In b + c both are promoted to int: 2.
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!