Topic 4 - Expressions Flashcards
What are expressions built from?
Variables, constants & operators.
What does the unary operator i = +1 do
j = -i?
increase by one, decrease by i
Do all binary arithmetic operators allow integer and floating point operand mixing?
Yes except modulo.
What is the type of there result when you mix float and int with binary operators?
It always has type float
What happens when you use / and % operators with integers and true answer is has a decimal point?
The answer gets truncated (ie. all numbers after decimal and the decimal itself are dropped ie. truncated)
The behaviour when / and % are used with negative operands is what? (In C89 and C99)?
C89: implementation-defined C99: 10%3 > 1 10%-3 > 1 -10 % 3 > -1 -10 % -3 > -1
What is the order precedence?
postfix
prefix
unary, * ? %, + -
What is the binary operator associativity?
Left associative
In many programming languages, an assignment is a statement, however, in C, what is it called?
An assignment is an operator, just like +, * etc.
What is another name for an assignment statement?
A side effect - where the right side is computed and a side-effect is the computed value is assigned to the variable to the left
What is the = operator associativity?
Right-associative
ie. i = j = k = 0; is equal to:
i = (j = (j = 0));
What is an advantage of side-effects of assignment statements?
They can be chained together:
i = j = k = 0;
What’s an Lvalue?
a variable (object stood in computer memory, not a constant or the result of a computation)
Give examples of compound assignment operators:
+=, -=, *=, /=, %=
Operator precedence in compound assignments are like the usual or different?
Different:
i = j+k is same as:
i = i(j+k)