Wednesday, May 20, 2009

Arithmetic Operators

Arithmetic operators in C++

The five arithmetical operations supported by the C++ language are:

+ addition
- subtraction
* multiplication
/ division
% modulo


Operations of addition, subtraction, multiplication and division literally correspond with their respective mathematical operators.

The only one that you might not be so used to see may be modulo; whose operator is the percentage sign (%). Modulo is the operation that gives the remainder of a division of two values.
For example, if we write:

a = 10 % 3;

the variable a will contain the value 2, since 1 is the remainder from dividing 10 between 3.

No comments:

Post a Comment