-->
Search here and hit enter....

Types of Operators in C language??

Hello Viewer! How are you I hope you well? In the previous lesson, we learn our first program in c language in this lesson we'll learn about operators...


our 1st question is what is operators:-
Operators are nothing but it is a symbol such as +,- etc.. there are many types of the operator in c programming language. some basic types of operators are...

  • Unary Operator
  • Arithmetic Operator
  • Bitwise Operator
  • Relational Operator
  • Logical Operator
  • Assignment Operator

1) Unary Operator: A unary operator is that operator that operates on a single operand in an expression or statement.

  • ++ :- Increment Operator
  • --   :- Decrement Operator
Note: 
 n++  :-   Post Increment
 here the meaning of "n++" is 1st take number and increment to 1. understand the following example.
 ex-

int n=1,p ;
p=n++;

O/p =  1. it means 1st assign the value of p = 1 and the increment it by 1. here the value of n is assigned to the p then the output is 1. 


++n   :-   Pre Increment
here the meaning of  "++n"  is 1st increment the value of n and then assign into p.
ex-
int n=1,p ;
p=++n;

here O/p= 2, it means 1st increment the value of n and then assigns into p.


n--   :-    Post Decrement
Similarly, As we know in the increment operator here also the same logic. understand with the example...

int n= 3, p;
p= n--;

O/p= 3, because here the 1st value of n assign into p and then decrement.



-- n  :-   Pre Decrement
Now you are able to understand these type of increment :) because you understand above with the example.


2) Arithmetic Operator: Arithetic operator are nothing but Addition(+), Substraction(-), Multiplication(*), Division(/) and Modulus Division(%)

Suppose in a large project/assignment we have almost all type of operator such as Addition, Subtraction, Multiplication, Division etc. so 1st we solve the "  *,  /  ,  %  " this operator.


Note:
(i) If between the two integers any arithmetic sign( such as Addition, Multiplication, Division, Subtraction) then the result will be Integer.

Integer/Integer = Integer

Example: 

11/5 = 2  (Right)
11/5 = 2.2 ( Wrong )
12/5 = 2  (Right)

(ii) If between the Real and Integer any Arithmetic operation ( such as Addition, Multiplication, Division, Subtraction ) then the result will be Real.

Real/Integer = Real
Integer/Real = Real
Real/Real = Real



3) Bitwise Operator: The operator are used to perform a bitwise operation like..,

Bitwise AND -   &
Bitwise OR -  |
Bitwise XOR -  ^
Bitwise NOT -  ~
Bitwise Right Shift -  >>
Bitwise Left Shift -  <<



4) Relational Operator: 
-Relational operator always yields result either 0 or 1.
-Every Non-zero value is True and Zero value is false.

In relational operator we 1st solve the " <, >, <=, >= " and after solving the relation we have to solve "   ==, != " relation. let's understand the given example
Program:


#include
int main()
{
int n;
n=5>4>3 ; // left to right
printf("\n%d", n);
}


Output: 0 or False, because we know 5 greater than 4 than here the value is 1 and 1 not greater than 3 hence these are false.




5) Logical Operator: These operators are used to combine two or more conditional expression in a statement.

Logical AND  -  &&
Logical OR  -   ||
Logical NOT  -  !


6) Assignment Operator: Assignment operator is used to assigning the new value to the variable.
suppose I have a value 10 and I need to store the value in " sum " variable so we can assign the value of a sum is equal to ( = ) 10.
These are two types of the assignment operator 
  • Simple Assignment Operator: (example - =)
  • Compound Assignment Operators ( example - +=, -=, *=, */ , &= )



In this post are so enough 4 today. I hope you like it.




Thank You 4 reading my blog!  if you have any problem or issue with this post please comment/contact.








FB COMMENTS ()