Search⌘ K
AI Features

Integers

Explore the fundamentals of integer types and arithmetic operations in D programming. Understand key concepts like overflow and truncation to manage whole number calculations effectively and avoid common pitfalls in software development.

Arithmetic operations

The basic arithmetic operations are addition, multiplication, division and subtraction. Arithmetic operations allow us to write much more useful programs.

Arithmetic operations
Arithmetic operations

Before going further, let’s have a look at the summary of arithmetic operations:

Summary of arithmetic operations/operators
Summary of arithmetic operations/operators

Most of those operators have counterparts that have an = sign attached: +=, -=, *=, /=, %=, and ^^=. These operators assign the result of the operation to the variable on the left-hand side.

variable += 10;

This expression adds 10 to the value of the variable and assigns the result to variable. After the operation, the value of the variable would be incremented by 10. It is the equivalent of the following expression:

variable
...