Operation priorities in C/C++


Any language expression consists of operands (variables, constants, etc.) connected with each other by operators. Operations are executed in a strict order. The value that determines a privilege to execute a certain operation is called a priority. The operation execution order can be regulated by use of parentheses.

Table 1. Operation priorities in C/C++.

Table 1. Operation priorities in C/C++.

You may often see errors in programs which are caused by the fact that it is easy for programmers to forget the exact priorities of operations (article on the topic). This is why professional developers do not feel embarrassed about using additional parentheses: this method secures them from accidental mistakes, and makes expressions more readable.

References


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++, and C#

goto PVS-Studio;
We use cookies for the analysis of events to improve our content and make user interaction more convenient. By continuing the view of our web-pages you accept the terms of using these files. You can find out more about cookie-files and privacy policy or close the notification, by clicking on the button. Learn More →
Do not show again