Information Technology Reference
In-Depth Information
Simple Arithmetic Operators
The simple arithmetic operators perform the four basic arithmetic operations, and are listed in
Table 8-6. These operators are binary and left-associative.
Table 8-6. The Simple Arithmetic Operators
Operator
Name
Description
+
Addition
Adds the two operands.
-
Subtraction
Subtracts the second operand from the first.
*
Multiplication
Multiplies the two operands.
/
Division
Divides the first operand by the second. Integer division rounds the
result toward 0 to the nearest integer.
The arithmetic operators perform the standard arithmetic operations on all the pre-
defined simple arithmetic types.
The following are examples of the simple arithmetic operators:
int x1 = 5 + 6; double d1 = 5.0 + 6.0;
int x2 = 12 - 3; double d2 = 12.0 - 3.0;
int x3 = 3 * 4; double d3 = 3.0 * 4.0;
int x4 = 10 / 3; double d4 = 10.0 / 3.0;
byte b1 = 5 + 6;
sbyte sb1 = 6 * 5;
Search WWH ::




Custom Search