COMP 002 - Reviewer - Basic Program Structure
COMP 002 - Reviewer - Basic Program Structure
ARITHMETIC RELATIONAL
OTHER OPERATORS
● Ternary ( ? true:false )
○ The ternary operator, also known as the conditional
operator, is a shorthand way of writing an if-else statement
in a single line. It evaluates the "condition" and returns the
value of "expression_if_true" if the condition is true, and
the value of "expression_if_false" otherwise.
● Comma
○ The comma operator allows multiple expressions to be
grouped together. It evaluates each expression from left to
right and returns the value of the last expression.
● Compound
○ Addition Assignment
■ The += operator adds the value on the right-hand side
to the variable on the left-hand side and assigns the
result to the variable on the left-hand side. It is a
shorthand for writing variable = variable + value.
○ Subtraction Assignment
■ The -= operator subtracts the value on the right-hand
side from the variable on the left-hand side and
assigns the result to the variable on the left-hand
side. It is a shorthand for writing variable = variable -
value.
○ Multiplication Assignment
■ The *= operator multiplies the variable on the
left-hand side by the value on the right-hand side and
assigns the result to the variable on the left-hand
side. It is a shorthand for writing variable = variable *
value.
○ Division Assignment
■ The /= operator divides the variable on the left-hand
side by the value on the right-hand side and assigns
the result to the variable on the left-hand side. It is a
shorthand for writing variable = variable / value.