liveBook · Manning

Operator

As explained in Modern C

An operator is a C symbol or token that specifies an operation on one or more operands.

An operator is a C symbol or token that specifies an operation on one or more operands. In a small computation, `size_t c = (a - b)*2;` uses `-` and `*` to compute a value, while `size_t d = a - b*2;` exposes how grouping affects the result. section 2.1 section 4.1.1

C uses operators for several distinct jobs:

  • `+`, `-`, and `*` perform arithmetic; unary `+` preserves a value and unary `-` produces its negative. section 4.1.1
  • `=`, used for initialization and assignment, modifies an object rather than merely computing a value. section 2.1 section 4.6
  • `==`, `!=`, `<`, `>`, `<=`, and `>=` compare operands and produce `false` or `true`, represented as `0` or `1`. section 4.3.1
  • `++` increments a variable by one; operators such as `<` can participate in control statements. section 2.1

Grouping and comparison as values

With `size_t a = 45` and `size_t b = 7`, `(a - b)*2` computes 76, whereas `a - b*2` computes 31 because parentheses enforce a preferred binding. A comparison can also become an index: `sign[(largeA[i] < 1.0)] += 1;` selects index `0` or `1` from the comparison result. section 4.1.1 section 4.3.1

   size_t a = 45;
   size_t b = 7;
   size_t c = (a - b)*2;
   size_t d = a - b*2;


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}],[{\"line\":2,\"ch\":3},{\"line\":2,\"ch\":9}],[{\"line\":3,\"ch\":3},{\"line\":3,\"ch\":9}],[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}],[{\"line\":2,\"ch\":3},{\"line\":2,\"ch\":9}],[{\"line\":3,\"ch\":3},{\"line\":3,\"ch\":9}],[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}],[{\"line\":2,\"ch\":3},{\"line\":2,\"ch\":9}],[{\"line\":3,\"ch\":3},{\"line\":3,\"ch\":9}],[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}],[{\"line\":2,\"ch\":3},{\"line\":2,\"ch\":9}],[{\"line\":3,\"ch\":3},{\"line\":3,\"ch\":9}]]"}
!@%STYLE%@!

Inspect the paired arithmetic expressions to compare explicit grouping with the binding of multiplication. section 4.1.1

How Modern C covers it

How deep it goes
Explains operator categories, unary forms, grouping, comparison results, unsigned arithmetic, and evaluation-order limits.
Examples
Uses size_t arithmetic, parenthesized expressions, comparison-based array indexing, and incrementing loop variables.
What you can do after
Apply C operators to calculate values, modify objects, compare operands, and use boolean results in arithmetic or indexing.
How it connects
Connects operators with operands, expressions, arithmetic, assignment, comparison, statements, control statements, and array indexing.

Also explained in

Compare how 7 books explain operator →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.