0% found this document useful (0 votes)
30 views

Operators

Uploaded by

Ratan Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Operators

Uploaded by

Ratan Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

OPERATOR

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

The operators can also be classified based on the task


1) Arithmetic operator
2) Relational operator
3) Logical operator
4) Increment / Decrement operator
5) Assignment operator
6) Conditional operator
7) Bitwise operator
8) Shift operator
ARITHMETIC OPERATOR

Arithmetic operators are used to perform the mathematical operations such as


addition , subtraction , multiplication , division and modulus.

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.

Assignment operators can also be used along with arithmetic operators.


OPERATOR EXAMPLE EQUIVALENT TO
= a=5 Assign the value
+= a+=b a = a+b
-= a-=b a = a-b
*= a*=b a = a*b
/= a/=b a = a/b
%= a%=b a = a%b
INCREMENT / DECREMENT OPERATOR

Increment operator is used to increment/ increase the value of an integer by 1.


Decrement operator is used to decrement/decrease the value of an integer by 1.

OPERATOR TYPES OPERATION


• Increase the value by one
++ i ( pre increment ) and use it
++ ( INCREMENT ) • Update
• Use the value
i ++ ( post increment ) • Increase the value by one
and update it
• decrease the value by one
-- i ( pre decrement ) and use it
-- ( DECREMENT ) • Update
• Use the value
i – ( post decrement ) • Decrease the value by one
and update it
CONDITIONAL OPERATOR

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.

Syntax to create conditional operator :


condition ? Statement1 : Statement2

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

Bitwise operators are used to performing the manipulation of


individual bits of a number.

OPERATOR~ DESCRIPTION

& (BITWISE AND) Bitwise AND

|(BITWISE NOT) Bitwise NOT

^( BITWISE OR) Bitwise OR

~ 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.

You might also like