x += 1; what is this in C?
1 Answers
An assignment statement evaluates the expression on the right side of the equal sign first and then assigns that value to the variable on the left side of the =. This makes it possible to use the same variable on both sides of an assignment statement, which is frequently done in programming. For example:
Â
int x = 3;
x = x + 1; /* x is now 4 */
Â
To shorten this type of assignment statement, C offers the +=Â assignment operator. The statement above can be written as
Â
x += 1; /* x = x + 1 */
Â
Â