Ad Code

Responsive Advertisement

operators of c language.

operators in C language :


in c language, the operator are used to perform many type of operation. there are many operator like

1) Arithmetic Operators.
 2) Relational operators.
 3) Logical operators.
 4) Conditional operators.
 5) Unary operator.
 6) Assigned operators.
 7) Bitwise operators.

1) ARITHMETIC OPERATORS : The arithmetic operators perform arithmetic operation. the arithmetic operators can operate on any built in data type. the arithmetic Operator are in below: this table show all the arithmetic operators.


different the ( %) operator : - it cannot be used with real operator. - Iit requires both operand to be integer and second should be noon - zero. like : a=2%0; - if the first operand is negative then answer is negative else positive.

example : 
      - 10%3=-1
      -10%-3=-1
      10%-3=1

example of all arithmetic operators :

 #include<stdio.h>
 void main()
 {
     Int a=10,b=2;
 
    printf("%d", a+b) ;
    printf("\n%d", a-b) ;
    printf("\n%d", a*b) ;
    printf("\n%d", a/b) ;
    printf("\n%d", a%b) ;
 }
 out put : 12 8 20 5 0

2) Relational operators :  relational operators are use to compare arithmetil and logical. Relational Operators compare their left side value with the right side value.

Example :



3)Logical operators : it is used in complex condition or compound condition. the result of logical operator is either true or false. list of logical operator is given below. Logical AND the result of logical AND will be true, if both the expressions are true


Example; a = 5, b = 2, c = l then a> b & b> c is evaluated to true, because a> b is true and b> c is also true. Precedence of logical operator is lower than equality operator but higher than logical OR. Associty is from left to right.

truth table of logical AND is given below (here l = true and 0 = false)

Logical NOT:  It is also known as unary operator as it requires only one operand Not operator takes an expression and is evaluated to true if expression is! false and vice versa.

 Example; value of a = 5, b = 2, c = l !(a> b) ! (5>2) ! (true) (because not true = false) False True table of logic is not given below
(here l = true and 0 = false) it's precedence is higher than arithmetic, equality, logical AND, logical OR operator l. its associated is from right to left. 

4) Unary Operator : Unary operators require only one operand with operator. C allows two very useful operators not generally found in any other languages.



they are ++(increment) and - - (decrement) operator. the operator ++ adds 1 to the operand, and - - subtract 1.both are unary operator and takes the following form.

   ++m and m++
   - - m and m--

we use increment and decrement in for and while loops.



 Example :
 #include<stdio.h>
 void main ()
 { 
      Int y, m=5; 
     y=m++;
     printf("1) y=%d and m=%d", y, m) ;

     y=++m;
    printf("2) y=%d and m=%d", y, m) ;

    y=m--;
    printf("3) y=%d and m=%d", y, m) ;

     y=--m;
     printf("4) y=%d and m=%d", y, m) ;

 }

out put : 1) y=5 and m=6.
                 2) y=6 and m=6.
                3) y=5 and m=4. 
               4) y=4 and m=4. 


 So, it is a unary operators.

5) assignment : The assign operator is so simple. it only assign the values to other. " it assign the values right to left"


 Suppose that y and m two veriable. y=0,m=9; y=m;
 Than the y values is 9 because the m value is assigned in to y veriable.

6) Conditional  operators (? :) :

 it is also known as ternary operator as it requires three operands.

  Syntax: (test expression)? expression1 : expression 2;

 where test expression, expression1, expression 2 are expressions. First test expression is evaluated if it comes to true expression 1 is executed and if the expression is comes false than the second expression2 is executed.

Example : a=10,b=15; x=(a>b)? a:b; here a>b 
if the condition is true than x=a means x values become 10 and
if the condition is false than x=b means x values is 15. 




 So, it is a ternary Conditional operators. ❮ Previous                                                      Next ❯

Post a Comment

0 Comments