ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
int a = 10;
int b = a++ + a++;
printf("%d", a);- A. 11
- B. 12
- C. Undefined behaviour: a is modified twice without an intervening sequence point
- D. 10
Correct answer: C. Undefined behaviour: a is modified twice without an intervening sequence point
a++ + a++ contains two unsequenced modifications of the same variable a within one full expression, which is undefined behaviour regardless of what value a (or the sum) appears to end up with on any particular compiler.
More C Programming questions
- What is printed? c int x = 5; if (x = 10) printf("true %d", x); else printf("false %d", x);
- What is printed? c int a = 1, b = 0, c = 1; int result = a || b && c; printf("%d", result);
- What is printed? c int x = 5; int y = x++ + (x = 10); printf("%d", y);
- Assume a 64-bit LP64 ABI. What is printed? c int a = 5, b = 10, c = 15; int arr[3]; arr[0] = &c; arr[1] = &a; arr[2] = &b; int sum = 0…
- Assume a 64-bit LP64 ABI. What is printed? c int a = 100; int p = &a; int q = p; p = NULL; printf("%d %d", (p == NULL), (q));
- Assume a 64-bit LP64 ABI. What is printed? c struct Point { int x, y; }; void movePoint(struct Point p, int dx, int dy) { p->x += dx; p->y…