Operators in C Language

 

Operators

An operators is a symbol that tells the computer to perform certain mathematical or logical manipulations. In C there are large number of operators.

 

 

TYPES OF OPERATORS….

Arithmetic

                      Addition(+)

                     Subtraction(-)

                    Multiplication(*)

                      Divison(/)

                     Modulus(%)

Assignment

               A)Simple

                              Equal to(=)

               B)Shorthand

                                  +=     (Simple Assignment (i=i+1) in Shorthand(i+=1) 

                                  *=      (Simple Assignment (i=i*m-k) in Shorthand(i*=m-k) 

                                 %=      (Simple Assignment (i=i%m) in Shorthand(i%=m) 

Relational

                 A) Equality

                           Double equals(==)

                           Not equals(!=)

               B) Comparison

                         Less than(<)               

                        Greater than(>)

                        Less than equals to(<=)

                       Greater than equal to(>=)

Logical

                     Not(!)

                    And(&&)

                     Or(||)

Conditional

                   Single(?:)

                  Double(??::)

Increment/Decrement

                  Prefix(++x,--x)

                 Postfix(x++,x--)

Bitwise

               Shift(>>)

              Shift(<<)

             And(&)

Special

             Urnary(+,-)

              Comma(,)

             SizeOf

 

Arithmetic Operator------Arithmetic operator are the simplest and basic operator do arithmetic operations. These operator require two variable and are called binary operator.

Ex……int a,b,c

     a=3;

   b=2;

c=a+b;

Here a and b are operand and + is the operator. Operand may be a variable, a constant or an expression etc.

Assignment Operator-----Assignment Operator are used to assign the result of an expression to a variable.

Ex…..a=a+1;

= is the assignment operator(Simple)

a+=1;

This is the shorthand assignment operator, meanings are same.

Relational Operator------Relational operator are used to compare two values. The word relation means relationship between two variable or more.

Ex….

int a,b;

a=7;  

b=5;

if(a>b)

printf(”a is greater”);

Logical Operator----Logical Operator are used for logical operations. In this operator we use truth table for calculation.

OR(||)

IstValue is true             IIndvalue is true        IstValue||IInd value=True  

IstValue is true             IIndvalue is false        IstValue||IInd value=True              

IstValue is false             IIndvalue is true        IstValue||IInd value=True              

IstValue is false             IIndvalue is false        IstValue||IInd value=false            

          

AND(&&)

IstValue is true             IIndvalue is true        IstValue&&IInd value=True  

IstValue is true             IIndvalue is false        IstValue&&IInd value=false            

IstValue is false             IIndvalue is true        IstValue&&IInd value=false            

IstValue is false             IIndvalue is false        IstValue&&IInd value=false            

 

NOT(!)

Negative change into positive

Positive change into negative

 

Increment/decrement Operator----Increment or decrement operator is also called urnary operato because in this we use only one operand.

Ex…

A++     A--

++A     --A

Conditional Operator------Conditional Operator is used to carry out conditional operations. It can be used instead of if-else statement.

Ex……..

Expression1?Expression 2:Expression 3;

Int a,b,c;

a=5;

b=4;

c=a>b?a:b;

Printf(“%d”,c);

Expression------An expression is a combination of operand & operator s. It is the combination of two or more than two operands with an operator or many operators.

EX…..

Arithmetic expression                                                   Mathmetic Expression

(v-p)/(t+w)         change into mathmetical v-p                     v-p

                                                                                                    t+w

Bitwise Operator-----Bitwise operations are the testing, setting or shifting of the actual bits in a byte or word. Bitwise Operation should not be of float or double type. To understand these operators, we first need to understand the basic of binary number system.

Ex....

2     11

2    5---1(remainder)

2    2----1(remainder)

2    1----0(remainder)    

Output is….1011(lower to upper)

About Us

Rekha SetiaRekha Setia is a passionate blogger of Extra Computer Notes. if you have any ideas or any request me @