[ Team LiB ] 3.6 The Binary String

[ Team LiB ] 3.7 Variable Increment and Decrement Operators: ++, - Variable increment (++) and decrement (–) operators come in two flavors: prefix and postfix. These unary operators have the side effect of changing the value of the arithmetic operand, which must evaluate to a variable. Depending on the operator used, the variable is either incremented or decremented by 1. These operators are very useful for updating variables in loops where only the side effect of the operator is of interest. Increment Operator ++ Prefix increment operator has the following semantics: ++i adds 1 to i first, then uses the new value of i as the value of the expression. It is equivalent to the following statements. i += 1; result = i; return result; Postfix increment operator has the following semantics: j++ uses the current value of j as the value of the expression first, then adds 1 to j. It is equivalent to the following statements: result = j; j += 1; return result; Decrement Operator - Prefix decrement operator has the following semantics: –i subtracts 1 from i first, then uses the new value of i as the value of the expression. Postfix decrement operator has the following semantics: j–uses the current value of j as the value of the expression first, then subtracts 1 from j. Examples of Increment and Decrement Operators // (1) Prefix order: increment operand before use. int i = 10; int k = ++i + –i; // ((++i) + (–i)). k gets the value 21 and i becomes 10. –i; // Only side effect utilized. i is 9. (expression statement) // (2) Postfix order: increment operand after use. long i = 10; long k = i++ + i–; // ((i++) + (i–)). k gets the value 21L and i becomes 10L. i++; // Only side effect utilized. i is 11L. (expression statement) An increment or decrement operator, together with its operand can be used as an expression statement (see Section 4.3, p. 113). Page 111

Hint: This post is supported by Gama besplatan domen provider

Comments are closed.