Computer Science, asked by jaiswalishita009, 1 month ago

a+=a++-++b+(--c) a=2, b=3, c=9​

Answers

Answered by anindyaadhikari13
2

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

  • The final value of a is - 8.
  • The final value of b is - 4.
  • The final value of c is - 8.

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

Given:

> a = 2

> b = 3

> c = 9

On evaluating the expression:

> a += a++ - ++b + --c

> a = a + a++ - ++b + --c

> a = 2 + a++ - ++b + --c  [Substitute the value]

> a = 2 + 2 - ++b + --c  [a remains 2, post-increment]

> a = 4 - ++b + --c  [a becomes 3]

> a = 4 - 4 + --c  [b becomes 4, pre-increment]

> a = --c

> a = 8 [c becomes 8, pre-decrement]

Therefore:

\sf\implies\begin{cases}\sf a=8\\ \sf b=4\\ \sf c = 8 \end{cases}

Which is our required answer.

\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

Answered by preetham44
0

Answer:

why do u want kaka thenannea

Similar questions