...

/

Basic Arithmetic Operations on Integers

Basic Arithmetic Operations on Integers

This lesson digs into the basic arithmetic operations on integers.

We will take advantage of the .min and .max properties below, which we have seen in the fundamental types lesson. These properties provide the minimum and maximum values that an integer type can have.

Increment: ++ #

This operator uses a single operand (usually a variable or an expression) and is written before the name of that variable. It increments the value of that variable by 1:

Press + to interact
import std.stdio;
void main() {
int number = 10;
++number;
writeln("New value: ", number);
}

As the program’s output shows, the value of number has been updated.

New value: 11

The increment operator is the equivalent of using the += (add-and-assign) operator with a value of 1:

number += 1; // same as ++number

If the result of the ...

Access this course and 1400+ top-rated courses and projects.