ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
int a[3] = {1,2,3};
int *parr[3] = {a, a+1, a+2};
int **pp = parr;
*(*pp + 1) += 10;
printf("%d %d %d", a[0], a[1], a[2]);- A. 11 2 3
- B. 1 2 13
- C. 1 12 3
- D. 1 2 3
Correct answer: C. 1 12 3
*pp is parr[0], which equals a (pointing at a[0]). *(*pp+1) dereferences a+1, i.e. a[1]; adding 10 makes a[1] become 12, leaving a[0] and a[2] untouched.
More C Programming questions
- What is printed? c typedef int (Op)(int,int); int a(int x,int y){ return x+y; } int b(int x,int y){ return x-y; } Op table[2] = {a, b}…
- What is printed? c int a[2][3] = {{1,2,3},{4,5,6}}; int rowptrs[2] = {a[0], a[1]}; int pp = rowptrs; for (int i = 0; i < 2; i++) for (int…
- Assume a 64-bit LP64 ABI (4-byte int, 8-byte pointers, natural alignment). What is printed? c struct Inner { char a; short b; }; struct…
- Assume unsigned int bitfields pack into 32-bit allocation units (typical gcc/Linux x86-64 behavior). What is printed? c struct BF {…
- Assume unsigned int bitfields pack into 32-bit allocation units and a zero-width bitfield forces the next field to a new unit. What is…
- On a little-endian 64-bit machine, what is printed? c union U { int i; char c[4]; }; union U u; u.i = 0x41424344; printf("%c%c%c%c"…