Default
Google

Operators: Arithmetic Operators

Applies To: C++Builder 1 or higher
Category: C++ Language

Arithmetic operators are used to perform mathematical operations such as addition or subtraction:
 
+: addition
-: subtraction (or unary minus)
/: division
*: multiplication
%: modulus
 
These five operators, also called binary mathematical operators are the same as the ones found on a calculator. (Modulus returns the remainder of a division.)
 
There are also complex arithmetic operators such as increment and decrement.
 
++: increment
--: decrement
 
They allow you to subtract or add 1 to the current value. For example, x++; is the same as x = x + 1;
 
These two operators can placed before (prefix mode) or after (postfix mode) the variable name. When used in prefix mode, the increment / decrement operators modify the item before its use. When used in postfix mode, the increment / decrement operators modify the item after its use. For example:
 
x = 5;
y = x++;
 
In the previous example, y is 5 and x is 6. If you use now the prefix mode:
 
x = 5;
y = ++x;
 
x and y equal 6.
 
Complex expressions are evaluated in the following order:
 
 1.
  Increment and decrement
 
 2.
  Multiplication, division, and modulus
 
 3.
  Addition and substraction
 
For example, the result of the following expression is 10:
 
x = 5 + 25 / 5;

C++Builder Developer's Network
Copyright © Yoto Yotov



Acquiring image from ProHosting Banner Exchange