ProgrammingHardHCL · Tech Mahindra pattern

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

Assume a 64-bit LP64 ABI. What is printed?
int x = 5;
int *p = &x;
int **pp = &p;
*pp = NULL;
printf("%d", p == NULL);
  1. A. 0
  2. B. 1
  3. C. Undefined behaviour: assigning NULL through a pointer-to-pointer
  4. D. Compile-time error: cannot assign NULL to *pp

Correct answer: B. 1

*pp dereferences pp to reach p itself (since pp holds &p), so *pp = NULL; actually reassigns the pointer variable p in the caller's scope to NULL — this is exactly the mechanism used to let a function modify a caller's own pointer. p == NULL is then true, printing 1.

More C Programming questions

Exams that ask this topic