Operator precedence determines the order in which operators are evaluated in an expression. Operators with higher precedence are evaluated 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, in 3 + 4 * 5, the multiplication happens first.
Click to reveal answer
intermediate
What does associativity mean in operator precedence?
Associativity defines the direction in which operators of the same precedence are evaluated. For example, left-to-right means operators are evaluated from left to right.
Click to reveal answer
beginner
How does parentheses ( ) affect operator precedence?
Parentheses have the highest precedence. Expressions inside parentheses are evaluated first, no matter what other operators are present.
Click to reveal answer
beginner
In the expression a = b + c * d;, which operation happens first?
The multiplication c * d happens first because * has higher precedence than +. Then the result is added to b, and finally assigned to a.
Click to reveal answer
Which operator has the highest precedence in C?
AParentheses ( )
BAddition (+)
CAssignment (=)
DLogical AND (&&)
✗ Incorrect
Parentheses have the highest precedence and force the expression inside them to be evaluated first.
What is the associativity of the subtraction operator (-) in C?
ALeft to right
BNo associativity
CRight to left
DDepends on compiler
✗ Incorrect
Subtraction has left-to-right associativity, so expressions like 10 - 5 - 2 are evaluated as (10 - 5) - 2.