a+=a++-++b+(--c) a=2, b=3, c=9
Answers
- The final value of a is - 8.
- The final value of b is - 4.
- The final value of c is - 8.
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:
Which is our required answer.
There are two types of increment/decrement operations.
- Post increment/decrement.
- 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
Answer:
why do u want kaka thenannea