ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
int a = 1, b = 2;
int result = !a == !b;
printf("%d", result);- A. Compile-time error: ! cannot be applied this way
- B. 0
- C. 3
- D. 1
Correct answer: D. 1
! has higher precedence than ==, so !a == !b parses as (!a) == (!b), never '!(a == b)'. !a is !1 = 0 (since a is nonzero/true). !b is !2 = 0 (b is also nonzero/true, so its logical negation is also 0). 0 == 0 is true, so result = 1.
More C Programming questions
- What is printed? c int x = 10; int y = x > 5 ? x > 8 ? 1 : 2 : 3; printf("%d", y);
- What is printed? c int i = 0; int arr[5] = {10, 20, 30, 40, 50}; while (i < 5) printf("%d ", arr[i++]); printf("%d", i);
- What is printed? c int a = 5; int b = (a > 3) ? (a = 10) : (a = 20); printf("%d %d", a, b);
- What is printed? c int x = 2, y = 3, z = 4; int result = x + y z - x / y; printf("%d", result);
- Assume a 64-bit LP64 ABI. What is printed? c int arr[5] = {1, 2, 3, 4, 5}; int start = arr; int end = arr + 5; int sum = 0; for (int p =…
- Assume a 64-bit LP64 ABI. What is printed? c int x = 42; void vp = &x; int ip = (int )vp; printf("%d", ip);