Click here to Skip to main content
15,906,301 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
int a=29;
a--;
//what is the out put of 'a' here and how?
a-=++a;
//what is the out put of 'a' here and how?


Please explain any one ,

Thanks for advance
Posted
Updated 30-Sep-14 13:04pm
v3
Comments
[no name] 30-Sep-14 18:45pm    
What output did you get when you ran this yourself? What output did you expect? Why was the output you got different than what you expected?
Sergey Alexandrovich Kryukov 30-Sep-14 18:55pm    
Don't waste time. Compile it and try out. Explain it using logical thinking.
—SA

1 solution

in first can your output will be 28

because your a will get decremented after line execution completes

and in second case your output will be

-1
because as per precedence (right to left)
first increment operation will be carried out and then
substraction operation will be carried out.
a= a - ++a
 
Share this answer
 

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