Recall & Review
beginner
What is operator precedence in Kotlin?
Operator precedence determines the order in which parts of an expression are calculated. Operators with higher precedence run before those with lower precedence.
Click to reveal answer
beginner
Which operator has higher precedence:
* (multiplication) or + (addition)?The multiplication operator
* has higher precedence than the addition operator +. So multiplication happens before addition.Click to reveal answer
beginner
How does Kotlin evaluate the expression
3 + 4 * 2?Kotlin first multiplies 4 by 2 (because
* has higher precedence), then adds 3. So the result is 3 + 8 = 11.Click to reveal answer
beginner
What role do parentheses
( ) play in operator precedence?Parentheses change the order of operations by forcing the expression inside them to be calculated first, regardless of operator precedence.
Click to reveal answer
intermediate
In Kotlin, which has higher precedence:
== (equality) or + (addition)?The addition operator
+ has higher precedence than the equality operator ==. So addition happens before checking equality.Click to reveal answer
In Kotlin, which operator is evaluated first in the expression
5 + 3 * 2?✗ Incorrect
Multiplication (*) has higher precedence than addition (+), so it is evaluated first.
What does parentheses do in the expression
(5 + 3) * 2?✗ Incorrect
Parentheses force the addition inside them to happen first, before multiplication.
Which operator has the lowest precedence in Kotlin?
✗ Incorrect
Assignment (=) has the lowest precedence among these operators.
In the expression
4 + 5 == 9, what happens first?✗ Incorrect
Addition has higher precedence than equality, so 4 + 5 is calculated first.
Which of these operators has higher precedence in Kotlin?
✗ Incorrect
Equality (==) has higher precedence than Logical AND (&&), Logical OR (||), and Assignment (=).
Explain operator precedence and how it affects the calculation of expressions in Kotlin.
Think about which parts of an expression Kotlin calculates first and why.
You got /4 concepts.
Describe how parentheses can change the result of an expression with mixed operators in Kotlin.
Consider the expression 3 + 4 * 2 versus (3 + 4) * 2.
You got /3 concepts.