find the output of this
Answers
- The output of the given code is – 130, 19, 9
Given:
> x = 12
> y = 22
On evaluating the expression:
> z = --x % --y * x - y--/x-- % y + y-- - x--
> z = 11 % --y * x - y--/x-- % y + y-- - x-- (x becomes 11, pre-decrement)
> z = 11 % 21 * x - y--/x-- % y + y-- - x-- (y becomes 21, pre-decrement)
> z = 11 * x - y--/x-- % y + y-- - x--
> z = 11 * 11 - y--/x-- % y + y-- - x--
> z = 121 - 21/x-- % y + y-- - x-- (y remains 21, post-decrement)
> z = 121 - 21/x-- % y + y-- - x-- (y becomes 20)
> z = 121 - 21/11 % y + y-- - x-- (x remains 11, post-decrement)
> z = 121 - 1 % 20 + y-- - x-- (x becomes 10)
> z = 121 - 1 + y-- - x--
> z = 120 + y-- - x--
> z = 120 + 20 - x-- (y remains 20, post-decrement)
> z = 140 - x-- (y becomes 19)
> z = 140 - 10 (x remains 10, post-decrement)
> z = 130 (x becomes 9)
Therefore:
So, the output for the given code is:
>> 130, 19, 9
Note: While solving this kind of problems, you have to know the operator precedence table so as to evaluate the expression.