0Pricing
C Academy · Lesson

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

  1. Arithmetic Operators
  2. Relational and Logical
  3. Assignment and Increment
  4. Operator Precedence
← Back to C Academy