Operators Precedence
When various operators are used within the same statement a problem arises which is which operation should be performed first. To solve this problem there is the concept of operator precedence. Operator Precedence is a set of rules that defines the priority for all the operators present in a programming language. The operation which has an operator with the highest priority will be executed first.
Example:
a= 4+5/10;
In the above given example if we solve the addition first then the answer will be 9/10=0.9 .
Now if we solve the division first then the answer will be 4 + 0.5 = 4.5 .
Out of this the second answer is a valid answer because the precedence of division is more than addition.
Therefore a=4.5
Operator Precedence and Associativity in Programming
We have many types of operators in a programming language. Operators serve many purposes. But when we have many operators within the same statement, Operator Precedence and Associativity come into the picture. They define which operator should be taken into account first. It is similar to the BODMAS rule we have learned in our school mathematics. In this article, we will see what is Operator Precedence and Associativity.
Contact Us