Multiple choice

What will be the output of the following program? void main() { int val=1234; int* ptr=&val; printf("%d %d",val,*ptr++); }

  1. 1234 1234

  2. 1235 1235

  3. 1234 1235

  4. 1235 1234

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The printf statement has *ptr++ as the second argument. The post-increment operator means the current value (*ptr=1234) is used for printf, then ptr is incremented. So printf receives val=1234 and *ptr=1234, printing "1234 1234". The pointer increment happens after the value is fetched.