Sunday, May 24, 2020

Arithmetic Operators – Part II


Remainder (Modulo)

Percent sign (%) is the remainder operator. In other programming languages it also known as modulo.

The result of the operator is a remainder left after the integer division.





Reasons for the above result:

14 // 4 gives 3 (integer quotient)
3 * 4 gives 12 (quotient & divisor multiplication)
14 – 12 gives 2 (remainder)

When we consider the below example,



The answer is not 3 but 3.0

Reasons for the above result:
12 // 4.5 gives 2.0
2.0 * 4.5 gives 9.0
12 – 9.0 gives 3.0

Addition

Plus (+) sign is the addition operator.








Subtraction / Unary & Binary Operators


Minus (-) sign is the subtraction operator. But we should notice this this symbol can change the sign of a number.

So, we have to say here there is an important distinction between unary & binary operators.


In subtracting scenarios, the minus operator expects two arguments.


From the above reason, the subtraction operator is considered to be one of the binary operators.

But the minus operator may be used in a different (unary) way.








There is also a unary (+) operator.





The operator preserves the sign of its only argument.


No comments:

Post a Comment