Subtraction operator -

The - (subtraction) operator yields the difference of its operands. Both operands must have an arithmetic or enumeration type, or the left operand must have a pointer type and the right operand must have the same pointer type or an integral or enumeration type. You cannot subtract a pointer from an integral value.

When both operands have an arithmetic type, the usual arithmetic conversions on the operands are performed. The result has the type produced by the conversions on the operands and is not an lvalue.

When the left operand is a pointer and the right operand has an integral type, the compiler converts the value of the right to an address offset. The result is a pointer of the same type as the pointer operand.

If both operands are pointers to elements in the same array, the result is the number of objects separating the two addresses. Behavior is undefined if the pointers do not refer to objects in the same array.

IBM extension The type of the result of pointer difference arithmetic will be ptrdiff_t ( defined in stddef.h) if the TERASPACE(*NO) compiler option is specified. If the TERASPACE(*YES) compiler option is specified, the result of the pointer difference arithmetic will be of type signed long long.

Related information



[ Top of Page | Previous Page | Next Page | Contents | Index ]