ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int mat[2][3] = {{1, 2, 3}, {4, 5, 6}};
int (*rowPtr)[3] = mat;
printf("%d %d %d %zu", (*rowPtr)[1], (*(rowPtr + 1))[2], **(rowPtr + 1), sizeof(rowPtr));- A. 2 6 4 4
- B. 1 6 4 8
- C. 2 5 4 8
- D. 2 6 4 8
Correct answer: D. 2 6 4 8
rowPtr points at the whole first row. (*rowPtr)[1] is mat[0][1]=2. rowPtr+1 points at the second row; (*(rowPtr+1))[2] is mat[1][2]=6. **(rowPtr+1) dereferences twice, landing on mat[1][0]=4. sizeof(rowPtr) is just the size of a pointer, 8 bytes on LP64, not the size of what it points to.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c int a[4] = {1, 2, 3, 4}; int p = a + 3; int q = a; printf("%ld %d %d", (long)(p - q), p, (p…
- Assume a 64-bit LP64 ABI. What is printed? c void swap(int a, int b) { int tmp = a; a = b; b = tmp; } int main(void) { int x = 1, y = 2…
- Assume a 64-bit LP64 ABI. What is printed? c int a = 1, b = 2, c = 3; int arr[3] = {&a, &b, &c}; int p = arr; p++; p += 10; printf("%d %d…
- Assume a 64-bit LP64 ABI. What is printed? c int x = 100; int p = &x; int pp = &p; int ppp = &pp; ppp = 200; printf("%d %d", x, pp);
- Assume a 64-bit LP64 ABI. What happens when this runs? c int create(void) { int x = 42; return &x; } int main(void) { int p = create()…
- Assume a 64-bit LP64 ABI. What is printed? c int a[3] = {1, 2, 3}; int p = a; printf("%d ", p++); printf("%d ", ++p); printf("%d", p);