ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int a[3] = {1, 2, 3};
int *p = &a[1];
printf("%d %d", p[-1], p[1]);- A. 2 3
- B. 1 3
- C. 3 1
- D. Undefined behaviour
Correct answer: B. 1 3
p points at a[1]. p[-1] is *(p - 1) = a[0] = 1 (valid, since it's still within the array's bounds). p[1] is *(p + 1) = a[2] = 3 (also valid). Output: 1 3.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c int x = 5; int p = &x; int pp = &p; pp = NULL; printf("%d", p == NULL);
- Assume a 64-bit LP64 ABI. What is printed? c int a = 10; int p = &a; int q = p; p = NULL; printf("%d %d", p == NULL, q);
- Assume a 64-bit LP64 ABI. What is printed? c int rows = 2, cols = 3; int matrix = malloc(rows sizeof(int )); for (int i = 0; i < rows…
- Assume a 64-bit LP64 ABI. What is printed? c int x = 1; int p = &x; int pp = &p; int ppp = &pp; printf("%d", ppp == &pp && ppp == pp &&…
- Assume a 64-bit LP64 ABI. What is printed? c int a[3] = {10, 20, 30}; int b[3] = {10, 20, 30}; printf("%d %d", a == b, a == b);
- Assume a 64-bit LP64 ABI. What is printed? c int globalArr[5] = {1, 2, 3, 4, 5}; void resetArr(void) { for (int i = 0; i < 5; i++)…