c = c + 3;
can be abbreviated with the addition assignment operator, +=, as
c += 3;
The += operator adds the value of the expression on the right of the operator to the value of the variable on the left of the operator and stores the result in the variable on the left of the operator. Any statement of the form
variable = variable operator expression;
where operator is one of the binary operators +, -, *, / or % (or others we will discuss later in the text), can be written in the form
variable operator = expression;
Thus, the assignment c += 3 adds 3 to c. Figure 7.12 shows the arithmetic assignment op-erators, sample expressions using these operators and explanations of the meaning of the operators.
Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.