0

# J=7..?? how it's working ? I m unable to evaluate or predict answers of such expression?plz guide me to clear my doubt?

5 Answers

+ 1

j = ++i + ++i + i;
j=A+B+C
is evaluated as follow:
j = (A + B) + C;
1) Evaluate A : increment i
-> now i is 1
2) evaluate B : increment i
-> now i is 2
3) evaluate A+B : add i to i
->That's 4
This sum is stored in new memory location separately to i, so is not changed when i is incremented again.
4) Evaluate C : increment i again
-> now i is 3
5) Add C (the last value of i) to the first sum : 4+3
Result is 7

+ 1

tysm Sir. ..since 2 nits I ws trying to find the conceptual reason

+ 1

Some more examples here:
https://code.sololearn.com/ceYh2erq9U7y/?ref=app
(you may want to link to yours in the comments!)

0

(...and, one should really *NOT* want to use this in production code !!! :-D)