Question 4
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int x = 5;
printf("%d %d %d\n", !x + 1, !(x + 1), !!x);
return 0;
}
- A 1 0 1 Correct
- B 0 0 5
- C 6 0 1
- D 1 1 1
Correct Answer: Option A
Unary ! binds tighter than +: !x + 1 is (!5) + 1 = 0 + 1 = 1. !(x + 1) is !6 = 0. !!x turns any non-zero value into exactly 1 – a common idiom.
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!