re-write the line as
i = (++k) + (k++) + (+k);
evaluation left to right:
i = 2 + (k++) + (+k) (k is incremented and assigned the value 2)
i = 2 + 2 + (+k) ( k's current value used, but with a side effect of incrementing k)
i = 2 + 2 + 3
i = 7;
Serdar
Originally posted by Saniya Ansari:
ok there is this question in Mughal's book.. i'm kinda confused although it seems easy..
public static void main(String args[]){
int k= 1;
int i= ++K + k++ + + k
System. out. prinln(i);
}
The answer is 7.. i'm not sure how.. HELP!