# Arithmetical, Relational and Logical Operators – Object Oriented Programming (OOP)

## Arithmetical, Relational and Logical Operators Object Oriented Programming(OOP) Third Semester | Second year BSc.CSIT | Tribhuvan University (TU)

Arithmetical Operator
An operator that performs an arithmetic (numeric) operation such as +,-,*,/, % is called arithmetic operator. Arithmetic operation require two or more operands. Therefore these operators are called binary operators. The table below shows the arithmetic operators:

Table: Operators Meaning with Example

 Operator Meaning Example Answer + Addition 7 + 4 11 – Subtraction 5 – 3 2 * Multiplication 8*5 40 / Division 15/3 5 % Modulo 5%2 1

Relational Operators
The relational operators shown in table below are used to test the relation between two values. All relational operators are binary operators and therefore require two operands. A relational expression return zero when the relation is false and a non-zero when it is true.

Table: Relational Operators with Example

 Operator Meaning Example == Equal to 8==8 != Not equal to 4!=8 > Greater than 5>3 < Less than 7<9 >= Greater than or equal to 8>=8 <= Less than or equal to 7<=7

Logical Operators
The ‘!’ operator is the C++ operator to perform the Boolean operation NOT. It has only one operand, located at its right, and the only thing that it does is to inverse the value of it, producing false if its operand is true and true if its operand is false. Basically, it returns the opposite Boolean value of evaluating its operand. Logical operators of C++ are given Table below:

Table: Logical Operators

 Operator Meaning && Logical AND || Logical OR ! Logical NOT

To understand the use of these operators in C++, let us take following example:
Example:
!(5==5) //evaluates to false because the expression at its right (5==5) is true.
!(6<=4) //evaluates to true because (6<=4) would be false
!true //evaluates to false
!false //evaluates to true

The logical operators && and || are used when evaluating two expressions to obtain a single relational result. the operator && corresponds with Boolean logical operation AND. This operation results true if both its two operands are true and false otherwise. The table shows the result of operator && by evaluating the expression (a && b);

Table: Use of && Operator

 Operand (a) Operand (b) Result true true true true false false false true false false false false

The operator || corresponds with Boolean logical OR. This operation results true if either one of its two operands is true, thus being false only when both operands are false themselves. To understand the use of || OR operator, let us take the possible results of (a || b) in table below;

Table: Use of || Operator

 Operand (a) Operand (b) Result (a || b) true true true true false true false true true false false false
(Visited 135 times, 1 visits today)

Posted By : | Comment RSS | Category : Third Semester
Subscribe Notes