C++ Additive Operators

The additive operators are:

These binary operators have left-to-right associativity.

Syntax

additive-expression :

multiplicative-expression
additive-expression + multiplicative-expression
additive-expressionmultiplicative-expression

The additive operators take operands of arithmetic or pointer types. The result of the addition (+) operator is the sum of the operands. The result of the subtraction (–) operator is the difference between the operands. If one or both of the operands are pointers, they must be pointers to objects, not to functions.

Additive operators take operands of arithmetic, integral, and scalar types. These are defined in Table 4.2.

Table 4.2   Types Used with Additive Operators

Type Meaning
arithmetic Integral and floating types are collectively called “arithmetic” types.
integral Types char and int of all sizes (long, short) and enumerations are “integral” types.
scalar Scalar operands are operands of either arithmetic or pointer type.

The legal combinations for these operators are:

arithmetic + arithmetic
scalar + integral
integral + scalar
arithmeticarithmetic
scalar scalar

Note that addition and subtraction are not equivalent operations.

If both operands are of arithmetic type, the conversions covered in Arithmetic Conversions in Chapter 3 are applied to the operands, and the result is of the converted type.