W1: Expressions Flashcards
How does evaluating expressions work?
The ALU (Arithmetic-logic-unit) evaluates the instructions on integer values The FPA evaluates the instructions on floating-point values.
What expressions can the ALU process on integer types?
Arithmetic
Relational
Logical
Arithmetic expressions consist of:
Integral operands for processing by the ALU
Floating point operands for processing by the FPA
What are the binary operations on integral (int and char) operands?
operand + operand operand - operand operand * operand operand / operand operand % operand - remainder of the division of left by right (division produces a whole number)
What are the unary operations on integral operands?
+ evaluates to the operand
- changes the sign of the operand
What are the binary operations on floating-point operands?
operand + operand
operand - operand
operand * operand
operand / operand
What are the unary operations for floating-point operands?
+ operand evaluates to the operand
- operand changes the sign of the operand
What are relational expressions?
C language supports 6 relational operations. A relational operation evaluates a condition. It compared two values and produces ‘1’ if the condition is true and ‘0’ if the value is false. The value is a type of int.
What are the 6 relational operations?
operand == operand: equal in value
operand > operand: left is greater than right
operand >= operand: left is greater than or equal to right
operand < operand: left is less than the right
operand <= operand: left is less than or equal to right
operand != operand: left is not equal to the right
What values represent true and false in C language?
0 for false
Any other value for true
Logical expressions take one of these forms:
operand && operand: both operands are true
operand || operand: one of the operands is true
operand ! operand: the operand is not true
What is deMorgan’s law?
A handy rule for converting conditions in logical expressions
“The opposite of a compound condition is the compound condition with all sub-conditions reversed, all &&s changed to ||s and vice versa”
What is a shorthand assignment?
Shorthand operators that combine an arithmetic expression with an assignment expression. The arithmetic expression is stored in the left operand.
What are the 5 binary shorthand assignment operators for integral operands?
Operand (operators) Operand
I += 4, i = i - 4 : add 4 to I and assign to I
I -= 4, I = I - 4: subtract 4 from I and assign to I
*=
/=
%=
What are the 4 unary operands for shorthand assignments?
++I : increment I by 1
I++
–i: decrement I by 1
I–