Which of the following statement is correct?
a) Operator precedence determines which operator is performed first in an expression with more than one operator with different precedence. Associativity is used when two operators of same precedence appear in an expression
b) Operator associativity determines which operator is performed first in an expression with more than one operator with different associativity. Precedence is used when two operators of same precedence appear in an expression.
c) Operator precedence and associativity are same.
.
d) None of the above
Answers
Answer:
a)
Explanation:
a) Operator precedence determines which operator is performed first in an expression with more than one operator with different precedence. Associativity is used when two operators of same precedence appear in an expression
Operator Precedence: Operator precedence is the priority of the operators used in an expression. In computers, operator precedence is almost as equal to the precedence in Mathematics (BODMAS - Brackets of Division Multiplication Addition and Subtraction). The only difference is that Division and Multiplication have the same precedence.
Operator Associativity: There are two types of associativity.
1) Left Associativity - The operations start from left to right.
2) Right Associativity - The operations start from right to left.
Answer:
- a) Operator precedence determines which operator is per formed first in an expression with more than one operators with different precedence. Operators Associativity is used when two operators of same precedence appear in an expression. Associativity can be either Left to Right or Right to Left.