C7: Operators and Expression Flashcards
What is an expression?
An expression is a formula that describes how to compute a value.
What does it mean to evaluate an expression?
Evaluating an expression means computing the value of an expression
Give an example of a simple expression.
A constant (14) or a variable (a).
Is assignment an operator or a statement in C?
In C, assignment is an operator. The assignment (right to left) then evaluates to a value.
What is a sequence point?
“any point in a computer program’s
execution at which it is guaranteed that all side effects
of previous evaluations will have been performed, and
no side effects from subsequent evaluations have yet
been performed.” (Wikipedia)”
OR
a point in the evaluation of a function when all side effects of operators so far encountered are guaranteed to be complete
What is the use of sequence point?
Sequence points determine when the side effects of an expression are determined and sequence point rules make some expressions undefined.
What are some defined sequence points?
Between evaluation of function designator and actual
arguments in a function call and the actual call
Between evaluation of operands of &&, ||, comma
operator
Between evaluation of operands of ? : operator
At the end of a full declarator
Between evaluation of full expressions
Immediately before a library function returns
Immediately before and after each call to a comparison
function
What is an expression statement?
An expression statement is simply an expression followed by a semicolon. (An expression is a formula that describes how to compute a value.) This is because expressions can be combined into more complex expressions using operators and assignment is an operator in C. That means that a statement (with assignment) is an expression.
What is the general difference between expressions and statements and how is C special in that regard?
The general difference between expressions and statements is that expressions compute a value and statements have a side effect. In C, assignment operators create expressions so expression have a side effect in these so-called “expression statements”.