Operators
Operators
Operators are predefined symbol which is used to perform specific task on the
given data.
The data given as a input to the operator is known as operand.
Based on the number of operand operator are further classified into the following
Unary operator
Binary operator
Ternary operator
UNARY OPERATOR :
The operator which can accept only one operand is known as unary operator.
BINARY OPERATOR :
The operator which can accept two operand is known as Binary operator.
TERNARY OPERATOR :
The operator which can accept three operand is known as Ternary operator.
CLASSIFICATION OF OPERATOR
OPERATOR OPERATION
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus operator
(Remainder after division)
RELATIONAL OPERATOR
Relational Operators are a bunch of binary operators used to check for relations
between two operands, including equality, greater than, less than, etc. They return a
boolean result after the comparison
OPERATOR EXAMPLE
== Is equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or Equal to
<= Less than or Equal to
LOGICAL OPERATOR
Logical operators are used to perform logical “AND”, “OR” and “NOT” operations.
They are used to combine two or more conditions/constraints or to complement
the evaluation of the original condition under particular consideration.
OPERATOR OPERATION
&&(Logical AND) If all the expression returns true
then this operator will return true
||(Logical OR) If any of one of the expression
return true then this operator will
return true
! (Logical NOT) It the result is true then it will
return false and vice versa
ASSIGNMENT OPERATOR
These operators are used to assign values to a variable. The left side operand of the
assignment operator is a variable, and the right side operand of the assignment
operator is a value. The value on the right side must be of the same data type of the
operand on the left side. Otherwise, the compiler will raise an error.
CONDITIONAL OPERATOR :
It is a ternary operator. We can use the ternary operator in place of if-else conditions.
If condition is true , statement 1 will execute , otherwise statement 2 will be executed.
OPERATION :
1) The return type of condition must be Boolean.
2) The return type of complete conditional operator will be same as statement 1
and statement 2.
BITWISE OPERATOR
OPERATOR~ DESCRIPTION
~ Bitwise NOT
SHIFT OPERATOR
shift operators are the special type of operators that work on the bits
of the data. These operators are used to shift the bits of the numbers
from left to right or right to left depending on the type of shift
operator used.
OPERATOR~ DESCRIPTION
>> The right shift operator moves all
bits by a given number of bits to
the right.
<< The left shift operator moves all
bits by a given number of bits to
the left.