Computer Science, asked by jaiswalnandini44743, 3 months ago

If int a=7,b=11,c=8 , then evaluate int x= (--a)+(b++) - (b%5) +(--c) + (a+c)- (c--) + (a+b);
options:
44
45
46

Answers

Answered by Anonymous
5

Given :

int a=7,b=11,c=8.

To Find :

int x = (--a) + (b++) - (b%5) +(--c) + (a+c)- (c--) + (a+b);

Solution :

  • a = 7
  • b = 11
  • c = 8

int x = (--a) + (b++) - (b%5) +(--c) + (a+c)- (c--) + (a+b);

= 6 + 11 - (12%5) + 7 + (6 + 7) - 7 + (6 + 12)

= 6 + 11 - 2 + 7 + 13 - 7 + 18

= 6 + 11 + 7 + 13 + 18 - 2 - 7

= 55 - 9

= 46

int x = (--a) + (b++) - (b%5) +(--c) + (a+c)- (c--) + (a+b);

= 46

The answer is 46.

Explanation :

  • Brackets have the highest precedence so firstly we have to solve the brackets.
  • Prefix decrement leads to the predecessor of the number. So, --a = 6; --c = 7
  • Postfix increment and decrement do not result in change of the number before the action. So, b++ = 11; c-- = 7
  • Modulus (%) helps us to get the remainder of the two numbers. So, 12%5 = 2; because 5 × 2 = 10; 12 - 10 = 2.
  • The last value of b will be incremented to 12.
  • Now as we have got all the values inside the brackets we can evaluate it as per the given binary operators.

Explore More :

  • Unary operator operands on single operand.
  • In case of Prefix, the increment and decrement operators(++, --) are written before the operand.
  • In case of Postfix, the increment and decrement operators(++, --) are written after the operand.
  • Binary operators operand on two operands.
Similar questions