Question
Consider the operator precedence and associativity rules for the integer arithmetic operators given in the table below.
| Operator | Precedence | Associativity |
|---|---|---|
| + | Highest | Left |
| - | High | Right |
| * | Medium | Right |
| / | Low | Right |
The value of the expression as per the above rules is __________
Official answer and solution
- Official answer
- 6
- From
- Official GATE 2024 answer key
Solution
Parenthesize and evaluate the expression strictly in decreasing order of custom precedence (+, then -, then *, then /).
Evaluating the expression step by step according to the given precedence table:
+(Highest precedence, Left-associative):
The expression reduces to:
-(High precedence, Right-associative):
The expression reduces to:
*(Medium precedence, Right-associative):
The expression reduces to:
/(Low precedence, Right-associative):
6
Evaluating - or / left-to-right instead of right-to-left as specified in the table.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2024 Computer Science and Information Technology - Set 1 (CS1)
- Question
- 33 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.