ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
int a = 4;
int b = ~a + 1;
printf("%d %d", b, -a);- A. -4 4
- B. -5 -4
- C. -4 -4
- D. 4 -4
Correct answer: C. -4 -4
~a + 1 is exactly the two's-complement negation formula: ~4 = -5, +1 = -4, which equals -a (-4) — confirming the identity ~x + 1 == -x. Both expressions print -4.
More C Programming questions
- What is printed? c int x = 1, y = 2, z = 3; int result = x < y < z; printf("%d", result);
- What is printed? c int a = 5; int b = a++ + ++a; printf("%d %d", a, b);
- What is printed? c int a = 0; int b = (a = 5) == 5; printf("%d %d", a, b);
- What is printed? c #define ISEVEN(x) ((x) % 2 == 0) #define ISODD(x) (!ISEVEN(x)) int main(void) { int n = 7; printf("%d %d", ISEVEN(n)…
- What is printed? c int x = 7; int result = x % 2 == 0 ? x / 2 : x 3 + 1; printf("%d", result);
- What is printed? c #define PRINT(x) printf(#x " = %dn", x) int main(void) { int count = 5; PRINT(count); }