In #1 statement ma will be 1 first, then ma will be incremented.
so, I think ma will be 2. But I got the output 1 from line #2. how the evaluation done here.
Also, as 2+1 = 3, I thought 3 will be the output of #3. But it is 5.
can any body please explain how the compiler evaluates this expression?
Venkata Saraswathi wrote:
=> it should be = ++1+(1) // here ma=2 yes?
why should we consider like ++3 + (1) instead of above.
First of all let me remind you Big Daddy of all Algebra Rule
LHS = RHS
1. Forget right hand side, first only deal with LHS - you will get ma.
2. OK now move to RHS - of course anything with in () is computed first. But who is computing in (). Its only assigning. You know assigning will be last.
3. So now come back to ++ma which will be 4. Now it is time to assign 1 in ma and retrive what is in ma, which is 1. Add it to 4 to become 5.