O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

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

Precedence

In the C language, expressions are evaluated according to certain rules of precedence. In other words, with no other guidance, a long expression containing several values and operators is evaluated according to a collection of rules that evaluates pairs of values according to something called associativity.

The standard rules follow the mathematical rules that evaluate expressions in the following sequence:

  • Anything in brackets

  • Multiplication

  • Division operations

  • Addition

  • Subtraction

  • Less than, and less than or equal to

  • Greater than, and greater than or equal to

  • Equals and not equals

  • Assignment

  • Assignment with operators (+=, -=, and so on)

There are more than the ones listed here, which is why I suggest one simple rule—Put everything in brackets ...

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