Order of Precedence for Operators in C++


The table below lists, ranks, and describes issues related to data type for the operators most commonly used within the C++ language. Those that are ranked the highest appear at the top. Operators within the same box in the table have equal ranking and will conform to the left-to-right associativity rule.

Operator Operation Type Action Operand Restictions Results

*

/

%

Arithmetic Multiplication Numeric See Note 1
Division Numeric See Note 1
Modulus Integer See Note 1

+

-

ArithmeticAddition NumericSee Note 1
Subtraction Numeric See Note 1

>

<

>=

<=

Relational Greater than Same Data Type True (1) /False (0)
Less than Same Data Type True (1) /False (0)
Greater than or equal Same Data Type True (1) /False (0)
Less than or equal Same Data Type True (1) /False (0)

==

!=

Relational Equal to Same Data Type True (1) /False (0)
Not Equal to Same Data Type True (1) /False (0)
&& Logical And Boolean True (1) /False (0)
|| Logical Or Boolean True (1) /False (0)

Note 1: Numeric data types can be mixed, but the result will be based on the largest most complex data type. This can be generally summarized in the results table that follows.

Operand 1 Operator(s) Operand 2 Result
Integer + or - Integer Integer
Integer + or - Float Float
Float + or - Float Float
Integer * or / Integer Integer
Integer * or / Float Float
Float * or / Float Float
Integer % Integer Integer
Integer % Float Error
Float % Float Error

PATH: Instructional Server> COP 2000> Examples>