ProgrammingHardIBM · Deloitte pattern
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?
- A. int (*p)[5]; and int *q[5];
- B. int p[5]*; and int q*[5];
- C. int *p[5]; and int *q[5];
- D. int *p[5]; and int (*q)[5];
Correct answer: D. int *p[5]; and int (*q)[5];
Array subscript [] binds tighter than the unary * in a declaration, so int *p[5] is parsed as (* of each of) p[5] — an array of 5 pointers. Parentheses override that: int (*q)[5] groups the * with q first, making q a single pointer to an array of 5 ints.
More C Programming questions
- 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);
- 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()…