If m = 8; find the value of m+ = m++ * ++m%2
Answers
Answer.
- The final value of m is 8.
Steps.
Given –
> m = 8
Expression to be evaluated –
> m+=m++ * ++m%2
> m += 8 * ++m%2 (Value of m is not changed, post-increment)
> m += 8 * ++m%2 (m becomes 9)
> m += 8 * 10%2 (m becomes 10, pre-increment)
> m += 80%2
> m += 0 (As 80 divided by 2 leaves remainder 0)
> m = 8 + 0
> m = 8
★ So, the final value of m is 8.
Learn More.
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.
Here, initialisation takes place first and then value is incremented.
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
Here, increment takes first and then value is initialised.