English

Evaluate the following expression where prefix and postfix increment and decrement operator is used. int rd=206, tf=20, yg=3, km=0; km = rd % tf++ + tf % ++yg ;

Advertisements
Advertisements

Question

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

int rd=206, tf=20, yg=3, km=0;

km = rd % tf++ + tf % ++yg ;

System.out.println ("RD=" +rd+ "TF=" +tf+ “YG=" +yg+ "KM=" +km);

Evaluate
Advertisements

Solution

First term (rd % tf++):

tf++ (Postfix): Uses the current value of tf (20) for the modulo calculation, then increments tf to 21.

206 % 20 = 6 (remainder of 206 divided by 20).

Second term (tf % ++yg):

++yg (Prefix): Increments yg first (from 3 to 4), then uses it.

Uses the updated value of tf (21). So, 21 % 4 = 1 (remainder of 21 divided by 4).

  • km = 6 + 1 = 7
  • rd = 206
  • tf = 21
  • yg = 4

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. (iv) | Page 45
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×