Friday, December 7, 2018

Operators in C Language

Operators

An operators specifies an operation to be performed .The variables constants can be join by various operator computer to perform mathematical or logical manipulation an expression.

C operators can be categories into following type :

1- Arithmetic operators
2- Relational operators
3- Assignment operators 
4- Conditional operators
5- Logical operators

1- Arithmetic operators

  Arithmetic operators are used for numeric calculations:
  They are mainly two type.
  •   Unary operators
  •   Binary operators

Unary operators:

                                      require only one operate.
 example  +x,+a, -c, etc

Binary operators:
                              requires two operators there are five binary arithmetic operators .

a=10 
b=5

OperatorName                        Examples
+Addition operatorsA + B = 15
Subtracts operatorsA − B = 5
*Multiply  operatorsA * B = 50
/Division operatorsB / A = 2
%Modulus operatorsB % A = 0
                             

2- Relational operators:

                                       Relational operator are used to compare values of two expression depending on their relation and an expression that contain relational operator is called  relational operator.
Of the relation is true than the value of relational operator (1) .And if the relation is false than the value of an expression is (0)

a=9
b=4
Operator Name                   Examples
>greater than(A >B)
(1)
>=greater than equal to(A>=b)
(1)
<Less than (A <b)
(0)
<=Less than equal to (A <=B)
(0) 
==equal to (A == B)
(0)
!=not equal to(A != B)
(1)

3- Assignment operators:

                                            A value can be stored in a variables with the use of assignment operation .

                             ex. 
                     assign 
                                 x = 2 
                                          variable
4- Conditional operators:
                                          Conditional operator is the ternary operator (? :) which require three expression as (Test expression ? expression 1: expression 2)

fastly the test expression is evaluated then -


1-if test expression is true then expression 1 is evaluate becomes value of over all conditional of expression.

2- if test expression is false then expression 2 is evaluate and becomes the over all result of conditional 
expression.

ex-
c=a>b?a:b

5- Logical operators:

                                   An expression that combine two or more expression is termed as logical operators . These operator return zero (0) for false and return one (1)  for true .

              
Operators                                    meaning
                                     
   &&                                                   AND operator
    
    |  |                                                      OR operator

    !                                                      NOT operator


No comments:

Post a Comment