ProgrammingHardIBM · Deloitte pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int a = 1, b = 2, c = 3;
int *arr[3] = {&a, &b, &c};
int **p = arr;
p++;
**p += 10;
printf("%d %d %d", a, b, c);- A. 1 2 13
- B. 11 2 3
- C. 1 2 3
- D. 1 12 3
Correct answer: D. 1 12 3
p is a pointer to the array of pointers, starting at &arr[0]. p++ advances it to point at arr[1], which holds &b. **p dereferences p to get arr[1] (&b), then dereferences that to reach b itself, and += 10 adds 10 to b, making it 12. a and c are untouched.
More C Programming questions
- 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);
- Assume a 64-bit LP64 ABI. What is printed? c int a = 5; int p1 = &a; int p2 = &a; printf("%d ", p1 == p2); printf("%d", p1 == p2);
- Assume a 64-bit LP64 ABI. What is printed? c int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; int p = (int )a; for (int i = 0; i < 6; i++)…
- Assume a 64-bit LP64 ABI (natural alignment, no #pragma pack). What is printed? c struct A { char c; int i; char d; }; struct B { int i…