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?
Asked
Active
Viewed 129 times
6

Blake Yarbrough
- 2,286
- 1
- 20
- 36

user2381832
- 126
- 1
- 11
-
3No one should ever write code like this. – duffymo Jul 16 '15 at 15:27
2 Answers
10
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 +

Madhawa Priyashantha
- 9,633
- 7
- 33
- 60
0
First all unary operator will be evaluated. Ex: - - 10 = +10.
Rest you can evaluate now.

Sachin Chandil
- 17,133
- 8
- 47
- 65