Wednesday, March 11, 2009

Puzzle 5 - Solution

The key to solving this puzzle is 'Operator Precedence'.
The post decrement operator '--' has precedence over the subtraction operator '-'.

The evaluation steps are as follows,

Step 1 : result = (a--)-b;
Step 2 : result = (5--)-1;
Step 3 : result = 4

The post decrement happens for 'a' so its value is decremented by 1.

The result is,

Value of a is : 4
Value of b is : 1
Value of result is : 4

Sorry no correct answers this week!

No comments:

Post a Comment

Solution for this question?