ProgrammingHardTCS NQT · Infosys pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int x = 5, y = 10, z = 15;
int *arr[3] = {&x, &y, &z};
int **p = arr;
printf("%d %d %d", *arr[1], **(p + 2), *p[0]);- A. 5 10 15
- B. 15 10 5
- C. 10 5 15
- D. 10 15 5
Correct answer: D. 10 15 5
arr is an array of pointers (array-of-pointers), each pointing at an int. *arr[1] dereferences arr[1] (&y), giving 10. p is a pointer to arr's first element; *(p+2) is arr[2] (&z), so **(p+2) is 15. p[0] is arr[0] (&x), so *p[0] is 5. Output: 10 15 5.
More C Programming questions
- Assume a 64-bit LP64 ABI. Which declaration makes p an array of 5 pointers to int, and which makes q a pointer to an array of 5 ints?
- Assume a 64-bit LP64 ABI. What is printed? c int mat[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (rowPtr)[3] = mat; printf("%d %d %d %zu"…
- 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);