Detailed Discription of C Language Operators Section-1

Engg.... | 00:22 | | | Best Blogger Tips
C operators

OPERATOR: Operator is a symbol that perform any operation.
OPERAND: On which operation is to be performed.

EXAMPLE:
a+b Where + is an Operator and a, b are the Operands
                  
C contains a rich set of operators. Operators used to perform basic airthmatic operations, manipulation of bits ,comparison etc. Operators operate on a single operand or two operands. C operators divided into 3 categories:
  1. Unary operators
  2. Binary operators
  3. Ternary operators
So Lets have a look on all Operators one by one:


TERNARY OPERATORS:
  • It takes three operands.
  • It is a conditional operator.
  • The two symbols that is ? and : are used in ternary operator.

<Condition> ?  <Value1> :  <Value2>

EXAMPLE:
M = a>b ? a : b;
Where Condition = a>b
Value1 = a
Value2 = b
If this condition a>b is True then a is assign to M but If condition is False then b is assign to M.
BINARY OPERATORS:
It takes two Operands. Binary operator are classified into 4 categories
  1. Airthmetic operators
  2. Logical operators
  3. Relational operators
  4. Bitwise operators
AIRTHMETIC OPERATORS:
These are used to perform the basic airthmatic operations such as multiplication,division,addition, substraction and Modulus Operator. It is used for finding remainder after an integer division. Operates on integer and float numbers. So there are two types of airthmetic operations:
  • Integer airthmetic
  • Floating point airthmetic.
INTEGER AIRTHMATIC:
If both the Operands are of integer type then Integer airthmetic is performed and result is integer value.
Ex: 
      If A=10 and B=20  then 
  • A+B=30
  • B-A=10
  • A*B=200
  • B/A=2

FLOATING POINT AIRTHMATIC:
If both the Operands are of float type then Floating point airthmetic is performed and result is Floating point  value.
Ex:
  If A=1.5 and B=2.5  then 
  • A+B =4
  • B-A=1
  • A*B=3.75
  • B/A=1
AIRTHMATIC OPERATORS:


 OPERATIONS 
     Addition
     Substraction
     Multiplication    
     Division
     Modulus 
 OPERATOR  
        +
        -
        *
         /
        %
 PRECEDENCE 
         2
         2
         1
         1
         1 


KEY POINTS ABOUT TABLE:
  1. Lowest Number Indicates Higher Priority.
  2. Highest Number Indicates Lowest Priority.
  3. Divide(/) Turncates the Fractional Part.
  4. Modulus Operator can not be used with Floating Point Number.

EXAMPLE:
If A=2 and B=5
  • A+B=7
  • B-A=3 
  • A*B=10
  • B/A=2
  • B%A=1


      Please Share it! :)
      Do you like this Story?

      Get Free Email Updates Daily!

      Follow us!

      1 comment: