int k=5. j = 9; k+ = k++ - ++j + k++. sopln (j+k)
Answers
Answered by
2
Given:
→ k = 5
→ j = 19
> k += k++ - ++j + k++
> k = k + k++ - ++j + k++
> k = 5 + 5 - ++j + k++ (k remains same, post-increment)
> k = 10 - ++j + k++ (k becomes 6)
> k = 10 - 20 + k++ (j becomes 20, pre-increment)
> k = -10 + 6 (k remains same, post-increment)
> k = -4
Therefore:
→ k = -4
→ j = 20
Sum of k and j is printed.
> k + j = 20 - 4 = 16
∴ Output: 16
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