int c=6; c+ = ++c * c-- / ++c % c--;
solve increment and decrement java
Answers
Answered by
3
- The final value of c is 6.
Given:
> c = 6
> c += ++c * c-- / ++c % c--
> c += 7 * c-- / ++c % c-- (c becomes 7, pre-increment)
> c += 7 * 7 / ++c % c-- (c remains 7, post-increment)
> c += 7 * 7 / ++c % c-- (c becomes 6)
> c += 7 * 7 / 7 % c-- (c becomes 7, pre-increment)
> c += 7 * 1 % 7 (c remains 7, post-increment)
> c += 7 % 7
> c += 0
> c = 6 + 0
> c = 6
★ So, the final value of c is 6.
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