+1 vote
79 views
#include<stdio.h>
int main(void)
{
int p = 1;
int q = 0;
q = p++ + p++;
printf("%d %d",p,q);
return 0;
}


Output is Showing $3,3$ How ?

edited | 79 views

+1 vote
Look at it this way
q=p++;
q=q + p++;

so the first time when p is encountered in this expression is treated as 1, the next ++ increments p by 1 so p becomes two. the second operand p is now treated as 2 so (1+2) becomes three. Now after that ++ is encountered which makes p=3. So this is why p becomes three and q becomes three
Step first- p=1 stored and then incremented

Step two- p=2 stored and then incremented to 3

Then q=1+2=3

And p has been incremented and and its value is 3...so final value stored in p is 3