Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include < stdio.h >
void main()
{
int i=2;
i=i++ * ++i * i * i++;
printf("%d\n\n",i);
}
Posted

1 solution

The trick here is the pre-increment happens before expression is evaluated and
post-increments happen *after* the expression is evaluated and assigned.

i=i++ * ++i * i * i++;

There is one pre-increment and two post-increments.

Above has four terms t1, t2, t3, and t4.

After applying the one pre-increment, i becomes 3.

t1, t2, t3, t4 = i so t1*t2*t3*t4 = 3^4 = 81.

Now the two post-increments are applied to i.
i plus 2 (the two post increments) becomes 83.

I do NOT recommend writing code this way.
 
Share this answer
 
v2
Comments
[no name] 6-Feb-14 19:49pm    
That's it.
kumar_11 7-Feb-14 3:39am    
That's great.
What about this if I write like..... ++i * ++i * i++ * ++i
Can You tell me the answer.
[no name] 7-Feb-14 13:45pm    
Assuming i starts at 2, there are three pre-increments so i+3=5.
5*5*5*5=625. Add the post-increment so i=626. At this point, you should be able to see the pattern.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900