OPERATORS

  • It is a symbol which takes one or more operants(values, variable, etc)
    and give some output.
  • Symbol are knowns as operator

Arithmetic Operators

  • This operators we are learning since from are childhood days.
  • This operators need two operants(variable, expression, values) and gives an output.
  • This operator are known as binary operator.
    as binary means two ,so this operator takes two operants.
Arithmetic Operators.
Operators Name
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo(Gives an Remainder)

Lets understand by an Simple Program


#include<stdio.h>


main(){
int a ,b,result_add,result_sub,result_mult,result_modulo;       // declaring variable
float result_div;     // declering the  variables


a=10;      // initializing the variables
b=15;      // initialization of variable


result_add = a+b;        //addition operator

result_sub = a - b;    // subractopn operator

result_mult = a*b;      // multiplication operator

result_div = b/a;        // Division operator

result_modulo = b%a;     // modulo operator (Gives the Remainder)

printf("Addition of two variable is %d\n",result_add);

printf("Subraction of two variable is %d\n",result_sub);

printf("Product of two variable is %d\n",result_mult);

printf("Division of two variable is %f\n",result_div);

printf("Remainder of two variable is %d\n",result_modulo);
}

Ouput:

Addition of two variable is 25
Subraction of two variable is -5
Product of two variable is 150
Quotient is 1.0000
Remainder is 5

Relational Operators

Relational Operators.
Operators Name
< Less Than
> Greater than
<= Less Than Equal to
>= Greater than Equal to
== Equal to
!= Not Equal to
Note:This operator are used in Control Structure(Loops,IF-else Statements,etc)
So,Examples of this, we will see in further modules.




Logical Operators

  • Logical operator are used to check two or more different condition and take
    decision According to their values.
  • This Operators comes in Binary Operator as well in Unary Operator(Need a single variable or expresions)
Logical Operators.
Operators Name
&& Logical AND
|| Logical OR
! NOT
Note:dont worry if you dont understand it now
Once we will start doing programs you will get an great understanding of it.

CONDITIONS

  • &&
    • This operator is a Binary Operator Which Works on Two Operants.
    • they evaluate According to their conditions
    • Below Table is truth table of AND Operator
    • Result is TRUE only if both the Operants are True.
      Operant1 Operant2 Result
      True True True
      True False False
      False True False
      False False False
  • ||
    • OR Operator is also an Binary Operator Which Works,
      On Two Operants
    • Below is TRUTH Table of OR operator
    • Result is True Even If One of the operants is True.
      Operant1 Operant2 Result
      True True True
      True False True
      False True True
      False False False
  • !
    • It is the Unary Operator ,which means it
      It works on Single Operant
    • It Gives the Complementary of the Operator.
    • Below is Truth Table for NOT Operator.
    • It gives the complement of operants.
      Operant1 Result
      True False
      False True

Unary Operators


  • Unary Operator Works on Single Operant.
  • Unary Operators.
    Operators Name
    + Unary Plus
    - Unary Minus
    ++ Increment
    -- Decrement
    ~ Bitwise Complement
    * Indirection
    < Address of
    ! Logical NOT
  • indirection,Address operators are used in Pointers chapter,this we will see in further modules.
  • Increment and Decrement behaves very badly.
  • Increment and Decrement.
    Operators Name Description
    ++m Pre increment this operator adds 1 to a variable and then assign it to a variable on left
    --m Pre Decrement this operator subtracts 1 from a variable and then assign it to a varaible on left
    m++ Post Increment this Operator assigns variable to the result and then adds 1 to a variable
    m-- Post Decrement this Operator assigns variable to the result and then subtracts 1 to a variable
Note:Mostly increment and decrement comes in Trace output like question,
because they are very messy.

Lets see One Trace the Output Question?

#include<stdio.h>


main(){
int a ,b;     // declering the  variables
a=10;      // initializing the variables
b=15;      // initialization of variable

b += ++a;

++b;

a++;

a += b++;

printf("a= %d\tb=%d",a,b);
}

Output

a=39    b=28
Note:we will see more example on "Simple Program" module




People Also Searched: