Example 1 — Compound assignment chain
Follow n through each update.
#include <stdio.h>
int main(void) {
int n = 10;
n += 5; printf("+= 5 -> %d\n", n);
n -= 3; printf("-= 3 -> %d\n", n);
n *= 2; printf("*= 2 -> %d\n", n);
n /= 5; printf("/= 5 -> %d\n", n);
n %= 3; printf("%%= 3 -> %d\n", n);
n <<= 3; printf("<<= 3 -> %d\n", n);
return 0;
} How It Works
- 24 / 5 is integer division, giving
4. 4 % 3leaves1.1 <<= 3shifts the bit left three places to8.
