int z, x = 5, y = -10, a = 4, b = 2;
z = x++ - --y * b / a; what number will z in the sample code above contain?
a) 5
b) 6
c) 10
d) 11
e) 12
int z, x = 5, y = -10, a = 4, b = 2;
z = x++ - --y * b / a; what number will z in the sample code above contain?
a) 5
b) 6
c) 10
d) 11
e) 12
Remember the following:
- The expression x++ evaluates to the current value of x, which is 5;
- The expression --y evaluates to the current value of y - 1, which is -11;
- The expression --y * b / a will be evaluated as (--y * b) / a since multiplication and division have the same precedence, so they are applied left to right;
- Since y, b, and a are all integers, the result of the division will be an integer value
Given all that, the answer should be obvious.
So the result will be 5 - (-11) * 2 / 4 = 10.5 ans assuming that the value is integer we get 10
ans will be 10
precedence of Unary operators are higher than Arithmatic operators.
x++ and --y are unary operators so these are evaluated first
then multiplication is performed ,
then division is performed ,
then subtraction is performed.
So the output is 10
Nice Question....................
I tryed But i do not know it is correct or not
first priority gives to / after * +-from lerft to right
z=5++ + --10 * 2/4
=5++ + -11 *1/2
5++-5
so answer is zero
i tryed my level best
Good Question
I have some doubt on your answer
first Precedence is for / na from left to right
so first 2/4 operation will perform
check it once
good work