ProgrammingHardTCS NQT · Infosys pattern

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

Assume a 64-bit LP64 ABI. What is printed?
int a = 10;
int *p = &a;
*p += 5;
p = p;
*p *= 2;
printf("%d", a);
  1. A. 15
  2. B. 30
  3. C. 25
  4. D. 20

Correct answer: B. 30

*p += 5 adds 5 to a through the pointer: a becomes 15. `p = p;` is a harmless no-op (self-assignment). *p *= 2 then doubles a through the same pointer: 15 * 2 = 30.

More C Programming questions

Exams that ask this topic