Computer Science, asked by jaiswalishita009, 1 month ago

x=5, x=x++*5+3*--x find the value of x​

Answers

Answered by anindyaadhikari13
2

\textsf{\large{\underline{Answer}:}}

  • The final value of x is - 40.

\textsf{\large{\underline{Solution}:}}

Given:

> x = 5

On evaluating the expression:

> x = x++ * 5 + 3 * --x

> x = 5 * 5 + 3 * --x   [x remains 5, post-increment]

> x = 25 + 3 * --x  [x becomes 6]

> x = 25 + 3 * 5  [x becomes 5, pre-decrement]

> x = 25 + 15

> x = 40

⊕ Therefore, the final value of x after evaluation is - 40.

\texttt{\textsf{\large{\underline{Know More}:}}}

There are two types of increment/decrement operations.

  1. Post increment/decrement.
  2. Pre increment/decrement.

Post Increment/Decrement: Here, operation takes place first and then the value is incremented/decremented.

Example:

> int a = 2;

> int b = a++;

> b = 2

Now, a = 3.

Pre Increment/Decrement: Here, value is first increment/decrement and then the operation is carried out.

Example:

> int a = 2;

> int b = ++a;

> b = 3

Also, a = 3

Similar questions