2.8.4 Arithmetic Operators

D provides the binary arithmetic operators that are described in the following table for use in your programs. These operators all have the same meaning for integers that they do in ANSI C.

Table 2.7 Binary Arithmetic Operators




Integer addition


Integer subtraction


Integer multiplication


Integer division


Integer modulus

Arithmetic in D may only be performed on integer operands or on pointers. See Section 2.10, “Pointers and Scalar Arrays”. Arithmetic may not be performed on floating-point operands in D programs. The DTrace execution environment does not take any action on integer overflow or underflow. You must specifically check for these conditions in situations where overflow and underflow can occur.

However, the DTrace execution environment does automatically check for and report division by zero errors resulting from improper use of the / and % operators. If a D program executes an invalid division operation, DTrace automatically disables the affected instrumentation and reports the error. Errors that are detected by DTrace have no effect on other DTrace users or on the operating system kernel. You therefore do not need to be concerned about causing any damage if your D program inadvertently contains one of these errors.

In addition to these binary operators, the + and - operators can also be used as unary operators as well, and these operators have higher precedence than any of the binary arithmetic operators. The order of precedence and associativity properties for all of the D operators is presented in Table 2.12, “D Operator Precedence and Associativity”. You can control precedence by grouping expressions in parentheses (()).