Reputation: 146
I have an expression in my code -
int i = 10 + + 11 - - 12 + + 13 - - 14 + + 15;
The value of the variable 'i' evaluates to 75, which is the sum of all the integers mentioned in the expression. How does the evaluation happen in this scenario?
Upvotes: 6
Views: 140
Reputation: 17829
First all unary operator will be evaluated. Ex: - - 10 = +10.
Rest you can evaluate now.
Upvotes: 0
Reputation: 9900
this evaluate as
int i = 10 + (+ 11) - (- 12) + (+ 13) - (- 14) + (+ 15);
evaluate to
int i= 10 +11+12+13+14+15;
and all become + so value is 75.note - -
is +
Upvotes: 10