C++ Deck 3 Flashcards
What is the associativity of:
?:
(Conditional)
Right-to-left
What is the associativity of:
= , += , -= , *= , /= , «= ,»_space;= , %= , &= , ^= , |=
(Assignment)
Right-to-left
What is the associativity of:
,
(Comma)
Left-to-right
What is the precedence level of a combined assignment operator?
i.e. += , -=, *=, etc.
The operator drops precedence to be equivalent to the precedence level of any other assignment operator regardless of the original precedence of its associated arithmetic operator.
=+ has the same precedence as =* for example.
What does this expression do: +=
variable = variable + expression
What does this expression do: -=
variable = variable - expression
What does this expression do: *=
variable = variable * expression
What does this expression do: /=
variable = variable / expression
What does this expression do: %=
variable = variable % expression
Are combined assignment operators (-=, *=, %=, etc.) Unary, Binary, or Ternary?
Binary. The variable is the L-value operand and the expression is the R-value operand.
Can the %= operator be used for float-point (aka double) values?
No. Just like the normal % (modulus), it can only be used for integer values.
When automatic conversion of data types occurs in C++, what is the general rule of thumb for ordering the types from smallest to largest without data loss?
char < short < int < long < float < double < long double
A compile time operation to explicitly change the type of a value from its current type to the target type.
static_cast
A conditional statement that allows you to execute a block of code based on a specified condition.
if statement
A statement that provides an efficient way to select one of many code blocks to execute based on the value of a variable or an expression. It compares the value against different cases and executes the code block associated with the matching case.
switch statement