ProgrammingVery hardWipro · Accenture · Capgemini pattern
What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int main(void) { int x = 7; int *p = &x; int old = (*p)++; int y = old + *p; printf("%d %d", x, y); return 0; }
- A. 8 14
- B. 7 14
- C. 8 15
- D. 8 16
Correct answer: C. 8 15
(*p)++ yields the old value 7 (stored in old) and then increments x to 8; the later *p reads the now-updated value 8 as a separate statement (no undefined ordering here); y = 7 + 8 = 15.
More C Programming questions
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…