We say that expresssions "evaluate" values and statement orders computer to "execute". But to me it seems like same terminology. What is the difference between execution and evaluation in C?
-
1It's more or less the same thing, don't bother with these english language subtleties. – Jabberwocky Jul 28 '16 at 12:33
4 Answers
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 evaluation starts? Before or after or at the same time of the execution? – haccks Jul 28 '16 at 12:41
-
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
.

- 5,271
- 9
- 40
- 61
-
-
-
@haccks: I think in the third paragraph I explained what I meant. I'm not trying to be 100% accurate, but rather to explain things in any easy way. In your example, technically both `y` and `z` are expressions, but I'd say it would make more sense to call them that if they were functions, like `x = y() + z();`. If they are numbers, calling them expressions seems overkill to me. And in this specific context I wouldn't say the full line is an expression, because it just confuses. I'm trying to show the difference between expressions and instructions. Saying that something is both doesn't help. – Fabio says Reinstate Monica Jul 28 '16 at 14:07
-
@Bauss I guess my previous comment is also for you. By the way, I have reworded the sentence to clarify that "roughly" doesn't apply just to the first sentence, but rather to both. That is, the definition of expression that I am giving is also a rough one. Again, I'm trying to make things simple, not accurate. That said, it would be nice to hear something from the OP... – Fabio says Reinstate Monica Jul 28 '16 at 14:12
-
@FabioTurati; An expression with semicolon at the end is a statement. I would not call them instruction until I am writing/reading an assembly code. – haccks Jul 28 '16 at 15:46
-
@haccks Thanks, edited. I've always used instructions and statements as synonyms, but it seems you are right. And statement is the word chosen by the OP after all. – Fabio says Reinstate Monica Jul 29 '16 at 09:21
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.

- 104,019
- 25
- 176
- 264
-
1"First execution takes place and then evaluation." Are you referring to the time when these processes begin? Or End? Do they overlap in time? Or are they mutually exclusive? – CinCout Jul 28 '16 at 12:45
-
-
1@haccks Thanks for the answer! When execution takes place, what does happen inside the compiler? – Jin Jul 28 '16 at 13:28
The way I have thought of it is: the term 'expression' is carried over from math terminology. Evaluation is defined as:
evaluate
To evaluate is to find the value of a numerical or algebraic expression.
Expressions have the following definition: (Boldface added for emphasis)
An expression in a programming language is a combination of one or more explicit values, constants, variables, operators, and functions that the programming language interprets (according to its particular rules of precedence and of association) and computes to produce ("to return", in a stateful environment) another value.
In programming, virtually every statement (or every statement worth writing) is composed to of many expressions. I have always used evaluation to refer to the computation of these expressions and execution to refer to the computation of the entire statement. This often coincides with distinctions around return value and side-effects as well. Full Statements usually have side-effects and expressions usually return a value of some sort.
-
Thanks for the answer rhmh! By the way, does execution happen before evaluation of expressions? – Jin Jul 28 '16 at 13:46
-
1@jwqwerty I'm not well versed on compiler semantics, but if an expression is part of a statement it must be evaluated to execute the function. However, it could be argued that execution has begun by evaluating the components. Rather than before or after, I would say evaluation occurs *during* execution. – rtmh Jul 28 '16 at 13:58