Chapter 4 Control Structures: Part 1 121 Assignment (Hp web site)

Chapter 4 Control Structures: Part 1 121 Assignment operator Sample expression Explanation Assigns -= d -= 4 d = d -4 1to d *= e *= 5 e = e * 5 20to e /= f /= 3 f = f / 3 2to f %= g %= 9 g = g % 9 3to g Fig. 4.12 Arithmetic assignment operators. (Part 2 of 2.) 4.12 Increment and Decrement Operators C# provides the unary increment operator, ++, and the unary decrement operator, –, which are summarized in Fig. 4.13. A program can increment the value of a variable called c by 1 using the increment operator, ++, rather than the expression c=c+1or c+=1. If an increment or decrement operator is placed before a variable, it is referred to as the pre- increment or predecrement operator, respectively. If an increment or decrement operator is placed after a variable, it is referred to as the postincrement or postdecrement operator, respectively. Preincrementing (or predecrementing) a variable causes the variable to be incremented (or decremented) by 1, and then the new value of the variable is used in the expression in which it appears. Postincrementing (or postdecrementing) the variable causes the current value of the variable to be used in the expression in which it appears, and then the variable value is incremented (or decremented) by 1. The application in Fig. 4.14 demonstrates the difference between the preincrementing version and the postincrementing version of the ++ increment operator. Postincrementing the variable c causes it to be incremented after it is used in the Console.WriteLine method call (line 14). Preincrementing the variable c causes it to be incremented before it is used in the Console.WriteLine method call (line 21). Operator Called Sample expression Explanation ++ preincrement ++a Increment aby 1, then use the new value of ain the expression in which a resides. ++ postincrement a++ Use the current value of a in the expression in which a resides, then increment a by 1. -predecrement –b Decrement bby 1, then use the new value of b in the expression in which b resides. -postdecrement b-Use the current value of b in the expression in which b resides, then decrement b by 1. Fig. 4.13 The increment and decrement operators.
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

Leave a Reply