# arithmetic operators in C++ and Distinguish between unary and binary arithmetic operators with examples.

Q1. What are arithmetic operators in C++? Distinguish between unary and binary arithmetic operators. Give examples for each of them.

Ans. C++ provides operators for five basic arithmetic calculations: addition, subtraction, multiplication, division and remainder which are +,-,*,and %.

Unary Operators

Operators that act on one operand are referred to as Unary Operators.

1. Unary +

The operator unary ‘+’ precedes an operand. The operand (the value on which the operator operates) of the unary + operator must have arithmetic or pointer type and the result is the value of the argument.

For example:

If a=5 then +a means 5.

1. Unary –

The operator unary – precedes an operand. the operand of the unary – operator must have arithmetic type and the result is the negation of its operand’s value.

For example,

If a=5 then –a means -5.

Binary Operators

Operators that act upon two operands are referred to as Binary Operators.

The arithmetic binary operator + adds values of its operands and the result is the sum of the values of its two operands.

For example,

4+20 results in 24.

1. Subtraction operator –

The – operator subtracts the second operand from the first.

For example,

14-3 evaluates to 11.

1. Multiplication operator *

The * operator multiplies the values of its operands. For example,

3 * 4 evaluates to 12.

1. Division operator /

The / operator divides its first operand by the second.

For example,

100 / 5 evaluates to 20.

1. Modulus operator %

The % operator finds the modulus of its operand relative to the second. That is, it produces the remainder of dividing the first by the second operand.

While using modulus operator both operands must be integer types.

For example,

19 % 6 evaluates to 1, since 6 goes into 19 three times with a remainder 1.

160 Views