English

Evaluate the following expression where prefix and postfix increment and decrement operator is used. int b = 6, d = 12,c = 0;  c = b++ + d-- + ++ b;

Advertisements
Advertisements

Question

Evaluate the following expression where prefix and postfix increment and decrement operator is used.

int b = 6, d = 12,c = 0; 

c = b++ + d-- + ++ b; 

System.out.println ("B=" + b+" D=" + d+" C=" +c);

Evaluate
Advertisements

Solution

  1. b++ (Postfix): Uses the current value of b (6) in the expression, then increments b to 7.
  2. d-- (Postfix): Uses the current value of d (12) in the expression, then decrements d to 11.
  3. ++b (Prefix): Increments b first (from 7 to 8), then uses this new value (8) in the expression.
  • C = 6 + 12 + 8 = 26
  • B = 8
  • D = 11
shaalaa.com
  Is there an error in this question or solution?
Chapter 1: Revision of Class 9 Syllabus - Exercises [Page 45]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 1 Revision of Class 9 Syllabus
Exercises | Q 3. (i) | Page 45
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×