ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int x = 100;
int *p = &x;
int **pp = &p;
int ***ppp = &pp;
***ppp = 200;
printf("%d %d", x, **pp);- A. 100 200
- B. 200 100
- C. 100 100
- D. 200 200
Correct answer: D. 200 200
ppp points to pp, pp points to p, p points to x. ***ppp dereferences three levels to reach x itself and assigns 200 to it. **pp also dereferences two levels (pp->p->x) and now reads the updated x, 200. Both reads show 200.
More C Programming questions
- 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…
- Assume a 64-bit LP64 ABI. What is printed? c union U { int i; char c[4]; double d; }; printf("%zu", sizeof(union U));