ProgrammingHardHCL · Tech Mahindra pattern
What is printed? Assume a 64-bit LP64 ABI (4-byte int).
What is printed? Assume a 64-bit LP64 ABI (4-byte int).
int a[3][2] = {{1,2},{3,4},{5,6}};
int (*p)[2] = a;
p = p + 2;
printf("%ld %d", (long)((char*)p - (char*)a), p[0][1]);- A. 16 4
- B. 8 6
- C. 16 6
- D. 32 6
Correct answer: C. 16 6
Each row of a is 2 ints = 8 bytes, so p (a pointer-to-row) advancing by 2 rows moves 16 bytes; the byte-cast difference confirms 16. p now aliases row a[2], so p[0][1] = a[2][1] = 6.
More C Programming questions
- Which statement about this code is correct? c int add(int a, int b) { return a + b; } int main(void) { int (fp)(int) = (int ()(int))add…
- What is printed? c 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]);
- 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 {…