Advertisements
Advertisements
Question
Evaluate the following expression where prefix and postfix increment and decrement operator is used.
int cm = 24, dc = 5, re = 8, bq = 1;
bq = cm/++dc + cm/re--;
System.out.printn("CM=" +cm +"DC=" +dc+" RE=" +re +“BQ=" +bq);
Evaluate
Advertisements
Solution
cm/++dc
++dc (Prefix): Increments dc first (from 5 to 6), then uses it.
24/6 = 4.
cm/re--
re-- (Postfix): Uses the current value of re (8) for the operation, then decrements re to 7.
- BQ = 4 + 3 = 7
- CM = 24
- DC = 6
- RE = 7
shaalaa.com
Is there an error in this question or solution?
Chapter 1: Revision of Class 9 Syllabus - Exercises [Page 45]
