plz Solve this above question ...plz donot give unnecessary answers if u don't know ....
Attachments:
Answers
Answered by
3
- The final value of 'a' is 7.
- The final value of 'b' is 1.
- The final value of 'c' is 14.
Given:
> a = 5
> b = 3
> c = 0
On evaluating the given expression:
> c = ++a + a++ + b-- - --b
> c = 6 + a++ + b-- - --b [a becomes 6, pre-increment]
> c = 6 + 6 + b-- - --b [a remains 6, post-increment]
> c = 12 + b-- - --b [a becomes 7]
> c = 12 + 3 - --b [b remains 3, post-decrement]
> c = 15 - --b [b becomes 2]
> c = 15 - 1 [b becomes 1, pre-decrement]
> c = 14
Therefore:
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
Similar questions