ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
int a = 4;
int r = ~a + 1 == -a;
printf("%d", r);- A. 0
- B. -5
- C. 4
- D. 1
Correct answer: D. 1
~ binds tighter than + and ==, so this is ((~a) + 1) == (-a). ~a+1 is exactly the two's-complement negation of a (a known identity), which always equals -a, so the comparison is true (1).
More C Programming questions
- What is printed? c int a = 3, b = 4, c = 5; int r = a + b == c ? 1 : 0; printf("%d", r);
- What is printed? c int a = 5; int b = a++, c = ++a; printf("%d %d %d", a, b, c);
- What is printed? c int x = 2, y = 3, z = 4; int r = x + y == z || x y == z + 2; printf("%d", r);
- What is printed? c int a = 7; int r = a % 3 + 2 a / 7; printf("%d", r);
- What is printed? c int a = 5, b = 10; int r = a & b == 10; printf("%d", r);
- What is printed? c char arr[] = {"alpha", "beta", "gamma"}; char p = arr; printf("%s %c %s", (p + 1), ((p + 2) + 1), p);