int i = 11;
i =i++ + ++i
System. out. println(i++ *++i)
Answers
int i = 11;
i = i++ + ++i;
System.out.println(i++ * ++i);
- The output of the given code is – 624.
Given:
> i = 11
On evaluating the given expression:
> i = i++ + ++i
> i = 11 + ++i ['i' remains 11, post-increment]
> i = 11 + ++i ['i' becomes 12]
> i = 11 + 13 ['i' becomes 13, pre-increment]
> i = 24
Now:
i++ * ++i
= 24 * ++i ['i' remains 24, post-increment]
= 24 * ++i ['i' becomes 25]
= 24 * 26 ['i' becomes 26, pre-increment]
= 624
★ So, the output of the given code is 624.
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