Friday, 14 February 2014

Operators

The operators are used to control/operate the various types of expressions within any program of the 'C' language.
In 'C' language,there are five types of operators:

Arithmetical Operators

  1. "+" : for addition
  2. "-" : for subtraction
  3. "*" : for multiplication
  4. "/" : for division
  5. "%": for modulation(to obtain the remainder).
Ex: 5/2 = 2.5 , 6/2 = 3 , 5%2 = 1 , 6%2 = 0.

Logical Operators

  1. "&&" : AND(Double Ampersand)
  2. "||" : OR(Double Pipe)
  3. "!" : NOT(Exclamation).

Relational Operators

  1. ">" : is greater than
  2. ">=" : is greater than or equal to
  3. "<" : is less than
  4. "<=" : is less than or equal to
  5. "==" : is equal to
  6. "!=" : is not equal to.

Assignmental Operators

    "=" : equals or equal to.
Ex: a = 5 ('5' is assigned to variable 'a') , while in a == 5 ('a' is compared with '5').

NOTE:Logical operators are never used independently , thy are used in combination with Relational Operators.

Short-Hand Operators

These operators are very useful as they decrease the time consumption.That's why they are known as Short-Hand Operators.
  1. "++" : incremental operator(increase by '1')
  2. "--" : decremental operator(decrease by '1')
  3. "+=" : increment by '1' or any real value
  4. "-=" : decrement by '1' or any real value
  5. "*=" : multiply by any value
  6. "/=" : divide by any value.
Ex: 1. k = k + 1  OR  k++
      2. k = k - 1  OR k--
      3. k = k + 2  OR k+=2
      4. k = k - 2  OR k-=2
      5. k = k * 3  OR k*=3
      6. k = k / 3  OR k/=3.

No comments:

Post a Comment