The key to today’s solution is ‘operator precedence’.
The multiplication operator (*) has higher precedence that the addition operator (+). Hence a statement like x = x*5+2 evaluates by multiplying x with 5 and adding 2 to the result and storing the result in ‘x’.
The shorthand assignment operators (+=, *= etc) have a lower precedence than the addition operator (+). Hence a statement like x *= 5+2 evaluates by first adding 5 and 2 and then multiplying the result (7) with x and storing the result in ‘x’.
The answer to last weeks puzzle is Value of X is : 35
Sorry no correct solutions this week!
No comments:
Post a Comment
Solution for this question?