typestar

Operators in C

Compound assignment, increment, and the ternary that replaces a short if.

int operator_tour(void) {
    int x = 10;
    x += 5;
    x -= 3;
    x *= 2;
    x /= 4;
    x %= 5;

    int i = 1;
    int post = i++;
    int pre = ++i;

    int larger = (post > pre) ? post : pre;
    return x + larger;
}

How it works

  1. x += 1 is shorthand for x = x + 1, and clearer at a glance.
  2. Postfix i++ yields the old value, prefix ++i the new one.
  3. The ternary is an expression, so it can initialize a variable.

Keywords and builtins used here

The run, in numbers

Lines
15
Characters to type
182
Tokens
74
Three-star pace
85 tpm

At the three-star pace of 85 tokens a minute, this run takes about 52 seconds.

Type this snippet

Step 1 of 7 in Operators & flow, step 8 of 35 in Language basics.

← Previous Next →