0
0
Kotlinprogramming~5 mins

Operator precedence in Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ABoth at the same time
BMultiplication (*)
CAddition (+)
DDepends on variable types
What does parentheses do in the expression (5 + 3) * 2?
AThey change the operators
BThey make multiplication happen before addition
CThey have no effect
DThey make addition happen before multiplication
Which operator has the lowest precedence in Kotlin?
AMultiplication (*)
BAddition (+)
CAssignment (=)
DEquality (==)
In the expression 4 + 5 == 9, what happens first?
AAddition (4 + 5)
BEquality check (== 9)
CBoth at the same time
DDepends on compiler
Which of these operators has higher precedence in Kotlin?
AEquality (==)
BLogical AND (&&)
CLogical OR (||)
DAssignment (=)
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.