

InterviewSolution
1. |
Int c=6; c+ = ++c * c-- / ++c % c--;solve increment and decrement java |
Answer»
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 – 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 |
|