You can check this course on my website.
Before you start reading, I want to ask you to like this article, so I will know that my work helps you ❤️
Before summarising Operators Precedence and Associativity, I would like to say that there are Bitwise and shift operators. In practice, they are used very rarely and I don’t think you will be needing them in the beginning, so I did not write about them and will not include them in the summary, but you can always read about them in the official documentation — Bitwise and shift operators and now let’s return to the summarising.
Each operator has its own precedence and operators with highest precedence are executed first.
Here, the multiplication operation has a higher precedence than addition, so it is performed first. But with parentheses, we could change the order of operations.
Also, if two operators have the same precedence, then the order of calculation is determined by associativity. As you remember from previous section Arithmetic Operators, there are two types of operators:
- Left-associative operators that execute from left to right;
- Right-associative operators that execute from right to left;
Table of Operators Precedence and Associativity
Previous article -> 2.9 Logical Operators
Next article -> 2.11 if else Statements
Join to our community in Telegram — https://t.me/itifico
If you want to support me, you can buy me a coffee. I send all donations to support the army of Ukraine.
Donations list:
- Dinesh Chintalapudi — 3$
- Unknown — 5$
- Neisy — 3$
- Unknown — 3$