Assignment and Increment
=, +=, ++, --.
The Assignment Operator
The = operator stores the value on its right into the variable on its left. It is not equality.
#include <stdio.h>
int main(void) {
int x;
x = 10;
printf("x = %d\n", x);
return 0;
}Assignment Is an Expression
In C, an assignment produces a value (the assigned value). This lets you chain assignments.
#include <stdio.h>
int main(void) {
int a, b, c;
a = b = c = 5;
printf("%d %d %d\n", a, b, c);
return 0;
}All lessons in this course
- Arithmetic Operators
- Relational and Logical
- Assignment and Increment
- Operator Precedence