ProgrammingHardIBM · Deloitte pattern
Assume 32-bit int. What is printed?
Assume 32-bit int. What is printed?
int x = 5;
int y = x-- - --x;
printf("%d %d", x, y);- A. 3 0, deterministically
- B. 3 2, deterministically
- C. Undefined behaviour: x is modified twice (by x-- and --x) with no sequence point separating them
- D. 4 1, deterministically
Correct answer: C. Undefined behaviour: x is modified twice (by x-- and --x) with no sequence point separating them
x-- - --x modifies x via two separate decrement side effects within the same expression (postfix and prefix), with no sequence point ordering them relative to each other — this is undefined behaviour in C, regardless of what any specific compiler's evaluation order happens to produce.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c struct Pair { int first; int second; }; struct Pair makePair(int a, int b) { return (struct…
- What is printed? c int main(void) { int a = 10, b = 3; printf("%d %d %f", a / b, a % b, (float)a / b); }
- What is printed? c int main(void) { char ch = 'A'; int code = ch + 1; printf("%d %c", code, (char)code); }
- What is printed? c int main(void) { int n = 17; int isPrime = 1; for (int i = 2; i i <= n; i++) { if (n % i == 0) { isPrime = 0; break; }…
- What is printed? c int main(void) { int a = 5; int b = a; b = b + 10; int p = &a; p = p + 100; printf("%d %d", a, b); }
- Assume a 64-bit LP64 ABI. What is printed? c struct Matrix3x3 { int data[3][3]; }; int trace(struct Matrix3x3 m) { int sum = 0; for (int i…