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
A ternary operator that can evaluate a simple if/else statement.
conditional operator
The specification of the order in which the individual statements, instructions or function calls of an imperative program are executed or evaluated.
control flow
The default control flow type in which statements are executed line by line.
sequential
Control flow types used for decisions; branching – choosing between two or more alternative paths.
Selection
(if, if/else, switch, conditional statements)
Control flow type used for looping – repeating a piece of code multiple times in a row.
Repetition
(while, do/while, for)
True or False: Any C++ expression that evaluates to a value (i.e. any R-value) can be interpreted as a true/false condition.
True
The meaning of this comparative operator: ==
equals
The meaning of this comparative operator: !=
is NOT equal
The meaning of this comparative operator: <
less than