What are operators?


fig :- operator 

 Operators are the special symbols that perform a specific and logical task to execute a program.
 some of the operators are given here let's discuss them below:-
a) Arithmetical operator:- these types of operators are used for general mathematical calculation   

Addition (+)   e.g. A+B 

Subtraction (-)   e.g. A-B 

Modulus (%) to find the remainder e.g. A%B 

Division (/)   e.g. A/B 

Multiplication(*)   e.g. A*B 

b) Relational operator :- relational operators are used to compare the value of variables.it return the value in true or false.  

operator 

Let's assume Age = 20 

Result  

<     (greater than) 

Age > 19 

False  

>    (less than ) 

Age < 25 

True  

<=  (less than equal to ) 

Age <= 18 

False  

>=  (greater then equal to)  

Age >= 20 

True  

= =  (equal) 

Age = = 18 

Fale   

Fig:- table of operator  

  • Logical operator:- logical operators are used to combining two or more two conditions at once. Let's be clear with an example, age = 25 

&& 

AND  

age >18 &&  age < 50   

|| 

OR   

age > 18 || age <50 

! 

NOT  

age >18 ! age <50 

c) Conditional operator:- if we have a simple if-else condition then we can use them here with conditional operators, let's be clear with  

Condition? Expression1  | expression2; 

Between given number, if we need to check the condition and print the greatest number then  

 

int a = 10;
int b = 5
int c;
C = (a > b) ? a | b;

  a  is greatest 

Condition is checked at first, if the condition is true it will print expression1, other-wise it will go for condition2. 

d) Assignment operator:- assignment operators are used to assigning the value to variables or to assign the result of an expression as a variable. For example  

Int a = 10; 

The value that is on the right side (10) will be assigned in a 

  • Increment/ decrement operator:- increment increase and decrement decrease the value of a variable by one(I++) (I--) in c. both increment and decrement are use in a single variable so they are also called unary operators. 

It is of two types they are:- 

  1. 1) Pre increment/ pre decrement:- Operators use before the variables, it firstly increments the value of a variable and then initializes to another variable. Let's be clear with an example:- 



#include <stdio.h> 
int main()   
{  
int x = 10;   
int yz;   
// y  = ++x;  
z  = -- x;   
// printf(" y =  %d\n", y);  // comment are used to print the correct value of a program (you can uncomment them and check it) 
printf("z = %d\n"z);  
return 0;  
 

 

Output  

x= 11  

y= 11 

z= 9 

  1. 2) Post increment/ decrement:- operators are use after the variables,  first, it initializes the value of a variable to another variable and increases or decreases the value of a variable. 



#include <stdio.h>
#include <conio.h>
int main()
{
  int x = 10;
  int yz;
  // y  = x++;
  z = x--; // printf(" y =  %d\n", y);  // comment are used to print the 
correct value of a program (you can uncomment them and check it)
  printf("z = %d\n"z);
  return 0;
  getch();
}

Output  

x= 11 

y= 10 

z= 10 

  • e) Bitwise operator:- bitwise operators are used to manipulating in bit level. We use this to check the bit or to shift the bit to right or left  

& 

Bitwise AND  

\ 

Bitwise OR 

^ 

Bitwise exclusive OR 

<< 

Bitwise left shift  

>> 

Bitwise right shift  

  • f) Special operator:- special operators are listed below let's discuss them here 

    1. 1) Size of operator:- they are used to check the size of variable and space in the memory, for example, int has 2 bit so it takes 2-bit memory. How to use this? Let's see:- 


    #include <stdio.h>
    #include <conio.h>
    void main()
    {
      int ca = 100;
      c = sizeof(a);
      printf("size of a is %d "c);
    }

    output  

    size of a is 4 

     

    1. 2) Comma operators:- these operators are used to link the same type of operators, it will be evaluated from left to right,  

    Int a, b, c, x; 

     a  = (b = 10, c = 20, x = a + b);  

    Output is x = 30. // 10 + 20  

    And value of  will be assign to a, so a = 30. 

0 Comments