Chapter 4: Expressions
Level 1 — Acquaintance
How C and Auto compose values through operators and evaluation.
Expressions are the workhorses of any program. Every computation — from adding two numbers to deciding which branch to take — ultimately reduces to evaluating an expression. C offers a rich set of operators; Auto keeps the same power but packages it in a safer, more readable form.
4.1 Operands and Operators
An operand is a value that an operator acts upon. An operator specifies what to do with its operand(s). C classifies operators by how many operands they take:
| Arity | C example | Meaning |
|---|---|---|
| Unary | -x | Negation |
| Binary | a + b | Addition |
| Ternary | a ? b : c | Conditional choice |
Auto uses the same classification but replaces the ternary ?: with an if/else expression syntax. The operator table below maps the most common C operators to their Auto equivalents.
| Category | C operator | Auto equivalent | Notes |
|---|---|---|---|
| Arithmetic | + - * / % | + - * / % | Identical |
| Increment/Decr. | ++ -- | x = x + 1 | No side-effect operators |
| Compound assign | += -= *= | x = x + y | Explicit assignment |
| Comparison | == != < > <= >= | == != < > <= >= | Identical |
| Logical | && || ! | and or not | Word forms in Auto |
| Ternary | a ? b : c | if a { b } else { c } | Expression form |
| Bitwise | & | ^ ~ << >> | same operators | Available in both |
Takeaway: Auto removes operators that modify objects in-place (
++,--,+=) and replaces them with plain assignment. This makes every expression's effect explicit.