CIS 1057 Chapter Notes - Chapter 4: Operand
Arithmetic Expressions cont.
● Type Conversion through Casts
○ Programmers can change the type of a value via casts
○ Casts can be implicit (e.g. compiler casts) or explicit, when the programmer writes out (type)value
to change the value to the type specified
● Expressions with Multiple Operators
○ Binary Operator = operator that takes two operands
■ e.g. multiplication (*) and division (/) operators
○ Unary Operator = operator that takes one operand
■ e.g. negation (-) and plus (+) operators
○ Rules for Evaluating Expressions
■ Parenthesis Rule
● All expressions in parentheses are evaluated separately
● Nested parentheses are evaluated from the inside out
■ Operator Precedence Rule
● Operators in the same expression are evaluated in a specific order:
● Unary first, /*% second, binary third
■ Associativity Rule
● Unary operators are evaluated right to left
● Binary operators are evaluated left to right
Document Summary
Programmers can change the type of a value via casts. Casts can be implicit (e. g. compiler casts) or explicit, when the programmer writes out (type)value to change the value to the type specified. Binary operator = operator that takes two operands e. g. multiplication (*) and division (/) operators. Unary operator = operator that takes one operand e. g. negation (-) and plus (+) operators. All expressions in parentheses are evaluated separately. Nested parentheses are evaluated from the inside out. Operators in the same expression are evaluated in a specific order: Unary operators are evaluated right to left. Binary operators are evaluated left to right. An error due to coding a real number as a finite number of binary digits. An error resulting from applying an arithmetic operation to operands of vastly different magnitudes, which causes the effect of the smaller operand to be lost. An error in which a very small computational result is represented as zero.