ProgrammingHardIBM · Deloitte pattern

Assume 32-bit int. What is printed?

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

Correct answer: A. 30

Both compound assignments act through the pointer on the real variable x. *p += 5 makes x = 10+5 = 15. *p *= 2 then makes x = 15*2 = 30. Each statement is fully sequenced before the next runs, so there's no ambiguity here.

More C Programming questions

Exams that ask this topic