ProgrammingHardTCS NQT · Infosys pattern

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

Assume a 64-bit LP64 ABI. What is printed?
int a = 5;
int *p = &a;
void *vp = p;
int *p2 = (int *)vp;
*p2 = 99;
printf("%d %d", a, *p);
  1. A. 99 99
  2. B. 5 5
  3. C. 99 5
  4. D. 5 99

Correct answer: A. 99 99

A void* can hold any object pointer's value without loss and be cast back to the correct type; p2 is really just another int* to a, so *p2 = 99 writes directly into a. Both a and *p (reading the same a) now show 99.

More C Programming questions

Exams that ask this topic