Assignment Operators in C
Plain = stores a value, but assignment is an expression in C — it yields the assigned value, which is why chains like a = b = 0 work (right-associative) and why = inside a condition compiles (usually a bug). The compound forms (+=, -=, *=, /=, %=, plus bitwise &=, |=, ^=, <<=, >>=) fold an operation into the store.
Assignment requires a modifiable lvalue on the left — array names, constants, and function results cannot be assigned to. Chained and embedded assignments trade brevity for review friction; most style guides restrict = to standalone statements.
= is an expression
a = b = 0 assigns right to left evaluating to 0 — useful for initialization chains, dangerous inside if conditions.
Compound operators
x += 3 means x = x + 3. Every arithmetic and bitwise operator has a compound form.
Left must be assignable
Only modifiable lvalues accept = — variables and dereferenced pointers qualify; literals, array names, and consts do not.
Keep = out of conditions
if ((n = read())) uses deliberate assignment-in-condition with doubled parentheses; bare if (x = 5) is virtually always a bug.
#include <stdio.h> int main(void) { int a = 0, b = 0; a = b = 10; a += 5; b *= 3; printf("%d, %d\n", a, b); return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.