An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators

  1. Arithmetic Operators :
  2. An arithmetic operator performs mathematical operations such as addition, subtraction, multiplication, division, modulo(%) etc on numerical values (constants and variables).

    Example : int a=10,b=20,c;
    c = a + b ; // c = 30
    c = a - b ; // c = -10
    c = a * b ; // c = 200
    c = a / b ; // c = 0
    c = a % b ; // c = 10
    NOTE : / operator gives quotient
    % operator gives reminder

  3. Relational Operators :
  4. Relational operators are used for comparison of the values of two operands. For example: checking if one operand is equal to the other operand or not, an operand is greater than the other operand or not etc. Some of the relational operators are (==, >= , <= ).

    Example : a > b
    NOTE : ==(double equal) operator is used to compare two operands

  5. Logical Operators :
  6. C provides three logical operators when we test more than one condition to make decisions. These are: && (meaning logical AND), || (meaning logical OR) and ! (meaning logical NOT).

    • && :- And operator. It performs logical conjunction of two expressions. (if both expressions evaluate to True, result is True. If either expression evaluates to False, the result is False)
    • || :- Or operator. It performs a logical disjunction on two expressions. (if either or both expressions evaluate to True, the result is True)
    • ! :- Not operator. It performs logical negation on an expression.


  7. Increment and Decrement Operators :
  8. Increment and Decrement Operators are useful operators generally used to minimize the calculation, i.e. ++x and x++ means x=x+1 or -x and x−−means x=x-1. But there is a slight difference between ++ or −− written before or after the operand.

    Applying the pre-increment first add one to the operand and then the result is assigned to the variable on the left whereas post-increment first assigns the value to the variable on the left and then increment the operand.

    Example :
    int a=10,b;
    b = ++a; // value of b = 11
    b = a++; // value of b = 10

  9. Bitwise Operators :
  10. Bitwise operators perform manipulations of data at bit level. These operators also perform shifting of bits from right to left. Bitwise operators are not applied to float or double

    • & :- Bitwise AND
    • | :- Bitwise OR
    • ^ :- Bitwise exclusive OR
    • << :- left shift
    • >> :- right shift

    Example :
    Assume A = 60 and B = 13 in binary format, they will be as follows −
    A = 0011 1100
    B = 0000 1101
    -----------------
    A&B = 0000 1100

    A|B = 0011 1101

    A^B = 0011 0001

    ~A = 1100 0011

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post