A strong answer
Operator precedence is a compile-time parsing rule that determines how operands group with operators—for example, in a() + b() * c(), multiplication has higher precedence than addition, so the expression parses as a() + (b() * c()). However, order of evaluation is a runtime question: in what temporal sequence does the CPU call a(), b(), and c() before combining their results? In C, the order of evaluation of most subexpressions and function arguments is unspecified—the compiler is free to call c(), then a(), then b() if that produces better register allocation.
Because evaluation order is unspecified, modifying a scalar object more than once—or modifying it and reading it for an independent purpose—without an intervening sequence point causes undefined behavior. In expressions like i = i++ or arr[i] = i++, the variable i has two unsequenced side effects (or an unsequenced read and write) in the same full expression. The C standard does not merely say the result is implementation-defined; it declares the entire program's behavior undefined, allowing optimizing compilers to emit arbitrary code.
Only four operators in C guarantee strict left-to-right evaluation with a sequence point between their operands: logical AND (&&), logical OR (||), the ternary conditional operator (? :), and the comma operator (,).
What the interviewer is listening for
- Clearly separates syntax grouping (precedence/associativity) from runtime execution order (evaluation order).
- States that function argument evaluation order (
f(g(), h())) is unspecified in C. - Explains why unsequenced modifications (
i = i++,f(i++, i++)) trigger undefined behavior rather than just picking one order.
Common mistakes
- Claiming that higher operator precedence (
*before+) forces the operands of*to be evaluated before the operands of+at runtime. - Confusing the comma operator
a(), b()(which guarantees left-to-right sequencing) with the commas separating function argumentsf(a(), b())(which do not). - Writing clever single-line expressions with multiple
++or--operators on the same variable instead of splitting them into separate statements.