Operators And Its Types in C Programming Language | Programming concepts | C Programming | Programming tutorials |

Hello, Guys in our last blog we learnt about TOKENS AND ITS TYPES , now in this blog we are going to know about OPERATORS AND ITS TYPES  in detail.

OPERATOR  is a symbol or a set of symbols which is used to perform an operation.

An operator can be classified based upon the following factors:

 1. ARITY
 
2. ASSOCIATIVITY
 
3. PRECEDENCE

 4. USAGES


1.ARITY
The number of operands upon which operators are applicable is known as ARITY.

Based upon the Arity ,there are 3 types of operators.
1.Uniary   (Arity - 1)
2.Binary    (Arity - 2 )
3.Ternary  (Arity - 3 )


2.ASSOCIATIVITY
If in an expression we are having multiple operators of same type or precedence ,then associativity is followed to evaluate the expression.
   
There are basically  2 types of operators based upon the associativity-
1. Left to Right
2. Right to Left


3.PRECEDENCE
All the operators enjoy their own priority and there priority helps them to be 
considered either first or second & etc in an expression.


4.USAGES
Depending upon the application there are 5 types of operators 

1. Arithmetic
2. Relational & logical
3. Assignment
4. Bitwise
5. Special

ARITHMETIC  OPERTORS:-

These operators are used for basic mathematical operations.

OperatorDescriptionExample
+Adds two operands.A + B = 30
Subtracts second operand from the first.A − B = -10
*Multiplies both operands.A * B = 200
/Divides numerator by de-numerator.B / A = 2
%Modulus Operator and remainder of after an integer division.            B % A = 0
++Increment operator increases the integer value by one.              A++ = 11
--Decrement operator decreases the integer value by one.                A-- = 9


RELATIONAL &  LOGICAL OPERATORS:-

These operators are used for relational and logical operations. RELATIONAL OPERATORS are used to compare between  2 variable or values.
LOGICAL OPERATORS are used to combine multiple expressions at a time.

                 LIST OF RELATIONAL & LOGICAL OPERATORS


OperatorDescription
and ( & )
true iff both operands are true
or ( | )
false iff both operands are false
not ( ! )
true iff operand is false
=true iff operands are equal
<true iff left operand is less than right
>true iff right operand is greater than right
!=
true iff operands are not equal
<=true iff left is less than or equal to right
>=true iff left is greater than or equal to right



ASSIGNMENT OPERATORS:-

Assignment operators are of 2 types-
1. Simple Assignment
2.Compound Assignment
 
 Both the simple and compound assignment is having arity 2.

OperatorDescriptionExample
=Simple assignment operator. Assigns values from right side operands to left side operandC = A + B will assign the value of A + B to C
+=Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand.C += A is equivalent to C = C + A
-=Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand.C -= A is equivalent to C = C - A
*=Multiply AND assignment operator. It multiplies the right operand with the left operand and assigns the result to the left operand.C *= A is equivalent to C = C * A
/=Divide AND assignment operator. It divides the left operand with the right operand and assigns the result to the left operand.C /= A is equivalent to C = C / A
%=Modulus AND assignment operator. It takes modulus using two operands and assigns the result to the left operand.C %= A is equivalent to C = C % A
<<=Left shift AND assignment operator.C <<= 2 is same as C = C << 2
>>=Right shift AND assignment operator.C >>= 2 is same as C = C >> 2
&=Bitwise AND assignment operator.C &= 2 is same as C = C & 2
^=Bitwise exclusive OR and assignment operator.C ^= 2 is same as C = C ^ 2
|=Bitwise inclusive OR and assignment operator.C |= 2 is same as C = C | 2


BITWISE OPERATORS :-

These operator is applicable to every bit of a number.These operators are only applicable to integers and characters not to real numbers.

                                        LIST OF BITWISE OPERATORS
      
&Binary AND Operator copies a bit to the result if it exists in both operands.(A & B) = 12, i.e., 0000 1100
|Binary OR Operator copies a bit if it exists in either operand.(A | B) = 61, i.e., 0011 1101
^Binary XOR Operator copies the bit if it is set in one operand but not both.(A ^ B) = 49, i.e., 0011 0001
~Binary One's Complement Operator is unary and has the effect of 'flipping' bits.(~A ) = ~(60), i.e,. 1100 0011
<<Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.A << 2 = 240 i.e., 1111 0000
>>Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.A >> 2 = 15 i.e., 0000 1111


 SPECIAL OPERATORS:-

OperatorsDescription
Comma,Comma operators are used to link related expressions together.
&This is used to get the address of the variable
*This is used as pointer to a variable
sizeof()This gives the size of the variable



Hope, You guys enjoyed this blog. In our next article, we will learn about the Variable and its types in C, and also about variable declaration and variable initialisation in C which will be very interesting to learn. If you have any suggestion / Advice for us, feel free to let us know in the comment section.You can also ask your doubts in comments section . We will be happy enough to know your feedback. Also, your appreciation will motivate us to add more to this blog.

Till then, Stay safe & Stay healthy. Have a nice day!!





Comments