What is Operators? Different types of Operators Used in C++ Language
Spread the love
Type operator (cast operator)
The word cast is used in the sense of “casting int a mold”. The compiler will automatically change one type of data into another field if it makes sense. For instance, if you assign an integer value to a floating- point variables. The compiler will secretly call a function to convert the ‘int’ to a ‘float.
Arithmetic operators
Arithmetic operators are used for arithmetic likes addition, subtraction, multiplication division etc. These are mainly five arithmetic operator used in c++ language.
Operators
|
Meaning
|
*
|
multiplication
|
/
|
division
|
%
|
modules(remainder after division)
|
+
|
addition
|
–
|
Subtraction
|
For examples, suppose a and b are two variables, then arithmetic operators used for different operations are:-]
A*b, a/b, a%b, a+b, a-b
Relations Operators
These create relationship between two operators. Relational operators are used for comparison purpose. The expressions have two operands and one relation operator is called relational expression. These are mainly six relational operators used in c++ language.
These are listed as in the below table:-
Relational Operators
|
Meaning
|
<
|
Less then
|
<=
|
Less then equal to
|
>
|
Greater then
|
>=
|
Greater then equal to
|
==
|
Equal to
|
!=
|
Not equal to
|
These operators are used in if statement,switch statement,conditional operation statement, while statement, do-while statement and for statement.
Logical operators
Logical operators are used logical operations. The operation are used for compound relational expression. when more then one relational expression occur in a c++ expression, using logical operation, then these are called compound relational expression. These are used in decision making statement and some looping statement like if, switch, do-while, while and for etc.
There are mainly there logical operations as listed in the table below:-
Logical operator
|
meaining
|
&&
|
Logical AND
|
||
|
Logical OR
|
!
|
Logical NOT
|
For example:-
And Logical operator
If (a>b&&a>c)
{
Cout<< “n A is greatest number”;
}
Using Or operator:-
If(roll no.==112||sex== ‘M’)
{
Cout<< “n ABSENT”;
}
Assignment operator
Assignment is performed with the operator. It means “take the right hand side and copy it into the left-hand side”. The value any constant variable or expressions that can produce a value. But 1 value must be a district named variable. For instance, you can assign a constant value to a variable (A=4;), but you cannot assign anything to constant value i.e. it can’t be an 1 value(4=A;).
Assignment operators are used for assigning an expression or value to a variable.
Assignment operators are of two types:-
Simple assignment operator
4. Conditional operator:-
Conditional operators are also called as ?: operators. These operators are used replacement of if statement.
The general syntax conditional operators is as:-
Exp.1? exp2: exp3;
|
Eg:-
a=10; b=5;
if(a>b)
{
c=a-b;
}
else
{
c=a+b;
}
The above if statement can be written by using condition operators as :-
C=(a>b)? a-b: a+b;
5. Bit-wise operators
The bit-wise operators allows you to manipulate individual bits in a number. Bit-wise operators perform Boolean algebra on the corresponding bits in the arguments to produce the result . These are used for the manipulation of binary data(bit).
There table for bit wise operator is a :-
Bit-wise operator
|
meaning
|
&
|
Bitwise AND
|
|(pipe symbol)
|
Bitwise OR
|
^
|
Bitwise X-OR
|
<<
|
Bitwise Left
|
>>
|
Bitwise Right
|
~ tilde
|
Bitwise Not
|
Design by Mohit Bhardwaj