ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
int x = 5;
x = x++ + 1;
printf("%d", x);- A. 6
- B. 7
- C. 5
- D. Undefined behavior: x is modified more than once without a sequence point
Correct answer: D. Undefined behavior: x is modified more than once without a sequence point
x++ modifies x, and the outer assignment also modifies x, with no sequence point ordering the two writes to the same scalar object. This is classic undefined behavior, not reliably 6.
More C Programming questions
- What is printed? c int i, j; for (i = 0, j = 10; i < 3; i++, j--) ; printf("%d %d", i, j);
- What is printed? Assume 32-bit int, two's complement. c unsigned int a = 5, b = 9; a = a ^ b; b = a ^ b; a = a ^ b; printf("%u %u", a, b);
- What is printed? c int flag = 0, mask = 2; flag |= mask == 2; printf("%d", flag);
- What is printed? c int a = 1, b = 2, c = 3; int arr[3] = {&a, &b, &c}; int p = arr; for (int i = 0; i < 3; i++) { (p + i) = 10; }…
- What is printed? (undefined behavior aside, assume typical stack layout where locals of adjacent calls can overlap after return) c int…
- What is printed? c char arr[] = {"one", "two", "three"}; char p = arr; printf("%s %c %s", p, ((p + 1) + 1), p[2]);