O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding Precedence

As you were probably taught when you first learned arithmetic, operators have a precedence: rules dictating in what order calculations are made. These are important to understand because they can dramatically affect the end result.

Table 3.2 lists the order of precedence in C for the arithmetic operators, but it's probably easiest just to follow these three rules:

1.
Multiplication and division take place before addition and subtraction.
2.
Operators with the same precedence level are executed from left to right.
3.
Use parentheses to guarantee your results.
Table 3.2. The precedence of operators from highest to lowest (those listed first will be executed first).
Rules of Precedence
Operator
()
++, --
+, - (Sign operators) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required