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
x += 1is shorthand forx = x + 1, and clearer at a glance.- Postfix
i++yields the old value, prefix++ithe new one. - The ternary is an expression, so it can initialize a variable.
Keywords and builtins used here
intoperator_tourreturnvoid
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.
Step 1 of 7 in Operators & flow, step 8 of 35 in Language basics.