What is the difference between execution and evaluation?

It's really close enough to not matter in almost all cases.

If we are to be very precise, I'd say that evaluation produces a result value and does not change state, while execution changes state and the result value is either not produced or is incidental and ignored.

Generally speaking, we evaluate expressions, we execute statements.

So, for example, if we have an if statement in C, we first evaluate the condition, then we execute (or not) the body.

The confusion is amplified because in C we have expressions that change status (assignment operator, increment/decrement operators) and the statements that are nothing but expressions.

So when you see

a = b+c;

in C, it's a statement that is executed, but the execution consists of evaluating the expression a=b+c, where the result (non-const reference to a) is discarded and the side effect (a changes its value) is important.


When a statement is executed then it comes to the action of evaluation of its expressions. First execution takes place and then evaluation.

In the snippet

int i = 5, j;
j = 10 + 5*i;

when the statement j = 10 + 5*i; is executed then evaluation of expressions j, 10, 5*i, 10 + 5*i and j = 10 + 5*i takes place. Note that first three can be evaluated in any order.


It's just a matter of linguistics. Expressions are evaluated, statements are executed. In both cases we can say that "something gets done", and I wouldn't worry too much about the difference.

To clarify: roughly, a statement is a line of code, and an expression is what you can find between brackets in an if() or while(), or on the right side of an equal sign.

For example, int x = 2 + 3; is a statement that declares a variable x and assigns to it the result of the expression 2 + 3, that is, 5.