Consider: double x = 5.0; double y = 3.0; x = (x * 1.5) - y; printf("x is %g\n", x); The multiplication and subtraction produce intermediate values; the assignment changes x; printf observes the resulting value. An expression is a C syntactic construct evaluated to produce a value, and some expressions also modify program state. Operators such as +, -, ==, and != act on operands; expressions may involve values, objects, or types. section 5.1 section 4.0
TAKEAWAY: C expressions combine several related operations.
- Value expressions perform arithmetic, comparisons, boolean work, conditional selection, and bit operations. section 4.0
- Object expressions access, assign, address, index, or modify objects. Assignment operators return the modified value, while ++ and -- differ between prefix and postfix forms. section 4.0 section 4.2
- Type expressions such as sizeof, _Alignof, and offsetof produce integer constants of type size_t. section 4.0
- Side effects make evaluation harder to follow: avoid modifying more than one object in a statement. section 4.2
Expressions as state transitions
Starting with x = 5.0 and y = 3.0, x = (x * 1.5) - y evaluates x to 5.0, computes 7.5, computes 4.5, and stores 4.5 in x. A compiler may replace unobservable intermediate work with equivalent code, provided the observable result remains unchanged. section 5.1
Table 4.1. Value operators The Form column gives the syntactic form of the operation, where @ represents the operator and a and possibly b denote values that serve as operands. For arithmetic and bit operations, the type of the result is a type that reconciles the types of a and b. For some of the operators, the Nick column gives an alternative form of the operator, or lists a combination of operators that has special meaning. Most of the operators and terms will be discussed later. (view table figure)
Browse the value-operator table to compare syntactic forms, operand restrictions, promotions, and result categories. section 4.0










