Arithmetic operators

Returns the result of specific arithmetic operation.

# Declarations

A operator+(A)
T* operator+(T*)
A operator-(A)

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
CWG 614C++98the algebraic quotient of integer division wasrounded in implementation-defined directionthe algebraic quotient of integerdivision is truncated towards zero(fractional part is discarded)
CWG 1450C++98the result of a / b was unspecified ifit is not representable in the result typethe behavior of both a / b anda % b is undefined in this case
CWG 1457C++98the behavior of shifting the leftmost 1 bit of apositive signed value into the sign bit was undefinedmade well-defined
CWG 1504C++98a pointer to a base class subobject of an arrayelement could be used in pointer arithmeticthe behavior isundefined in this case
CWG 1515C++98only unsigned integers which declared unsigned should obey the laws of arithmetic modulo 2napplies to all unsigned integers
CWG 1642C++98arithmetic operators allow their operands to be lvaluessome operands must be rvalues
CWG 1865C++98the resolution of CWG issue 1504 made the behaviorsof pointer arithmetic involving pointers to array elementundefined if the pointed-to type and the array elementtype have different cv-qualifications in non-top levelsmade well-defined
CWG 1971C++98it was unclear whether the rule resolving theambiguity of ~ applies to cases such as ~X(0)the rule applies to such cases
CWG 2419C++98a pointer to non-array object was only treated as apointer to the first element of an array with size 1in pointer arithmetic if the pointer is obtained by &applies to all pointersto non-array objects
CWG 2626C++98the result of built-in operator~ was simply’one’s complement’ without proper definitionthe result is phrased in termsof the base-2 representation
CWG 2724C++20the rounding direction of arithmetic right shift was unclearmade clear
CWG 2853C++98a pointer past the end of an object couldnot be added or subtracted with an integerit can

# See also