Operator Precedence

◀ C++ Keywords▶ Useful Functions
Amazon Knowing operator precedence well allows you to eliminate unnecessary brackets. Most programmers know basic operator precedence such as * and / are higher than + and -, but that’s not enough. You may also want to know, for example, if == or >= comes first. Consider the following code snippet:
char * cstar = “susan”;
char c = *++cstar;
The unary * and ++ have the same precedence, and the associativity is from right to left. We apply ++ first, then *. So c should be ‘u’.

You can find full operator precedence table at many places online or in C++ programming textbooks. When in doubt, write a simple program to test it. That way it sticks more than if you look it up somewhere. Remember, you can always use parentheses to force a certain order of evaluation.

Next let’s look at useful C++ functions!
◀ C++ Keywords▶ Useful Functions

Questions? Let me know!