ProgrammingHardWipro · Cognizant pattern

Assume a 64-bit LP64 ABI. What is printed?

Assume a 64-bit LP64 ABI. What is printed?
int x = 1;
int *p = &x;
int **pp = &p;
int ***ppp = &pp;
printf("%d", ppp == &pp && *ppp == pp && **ppp == p && ***ppp == x);
  1. A. 0
  2. B. 1
  3. C. Undefined behaviour: comparing pointers at three levels
  4. D. Compile-time error

Correct answer: B. 1

Each level of indirection is exactly what it's declared to be: ppp genuinely holds &pp, *ppp genuinely equals pp, **ppp genuinely equals p, and ***ppp genuinely equals x (1). Every comparison in this chain is true, so the overall && expression is 1.

More C Programming questions

Exams that ask this topic