NikitQa
NikitQa

Reputation: 143

What is evaluation?

I have been stumbling upon this term for a quite a while (man, math, programming, makefile, etc.) Am I understanding the term correctly? Evaluation is a calculation of the result of some expression, ex.:

a + b - expression

To evaluate it (get some result by number) we give variables value like so

a = 1, b = 1

Judging from that we get a result "2" ( which means we evaluated the expression to "2" with input values

a = 1, b = 1)

Upvotes: 1

Views: 401

Answers (1)

Eric Postpischil
Eric Postpischil

Reputation: 222272

C 2018 5.1.2.3 2 says “Evaluation of an expression in general includes both value computations and initiation of side effects.” So, yes, in large part evaluation is computing the value from some expression. In C, evaluation also includes side effects, such as the increment caused by x++, which affects x but does not contribute to the value of the expression it is in.

5.1.2.3 2 goes on to say “Value computation for an lvalue expression includes determining the identity of the designated object.” That is more about the semantics by which the C language is described than about performing a computation, so I will not discuss it further here.

6.5 1 tells us “An expression is a sequence of operators and operands that specifies computation of a value, or that designates an object or a function, or that generates side effects, or that performs a combination thereof.” So, for the value aspect of an expression, the expression specifies a computation, and evaluation performs that computation. The expression may also specify side effects, and evaluation performs those too.

Upvotes: 6

Related Questions