Search This Blog


Tuesday, September 17, 2019

Operator in C

Operator is a special symbol which is used to perform particular operation on operands.
example:- a+b-c   
              here: +,- are operators and a,b,c are operands.

There are some operators in C :-

  1. Arithmetic operator
  2. Relational operator
  3. Logical operator
  4. Assignment operator
  5. Multiple assignment operator
  6. Compound assignment operator/shortcut assignment
  7. Increment
  8. Decrement
  9. Comma operator
  10. Sizeof operator
  11. Bitwise operator
  12. Unary operator
  13. Binary operator
  14. Ternary operator/conditional

➤Arithmetic operator :-

This operator is used to perform arithmetic operation as addition, subtraction, multiplication,etc.
Operator
Meaning
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Remainder / Modulo division

example:-

10 / 4=2
10.0 / 4=2.5
10 / 4.0=2.5
10 % 4=2
4 % 10=4
-10 % 4=-2
10 % -4=2
-10 % -4=-2
-30.45 % 2.45= error

Note:1 If the value of operand is less than the value of second operand then remainder must be the value of first operand.
Note:2 The sign of remainder depends on only the sign of first operand.
Note:3 Real type operands cannot be allowed with modulo division.

➤ Relational operator :-

 This type of operator is used to compare between two numbers.
It returns Boolean value as zero(false) or one(true).
Operator
Meaning
< 
Less than
> 
Greater than
<=
Less than or equal to
>=
Greater than or equal to
!=
Not equal to
==
Equal to

example:-

20>=20 ➔ 1
30 > 40 ➔ 0
4 != 5   ➔ 1
4 == 6 ➔ 0
30 < 40 ➔ 1

➤ Logical operator :-

This operator is used to combine more than one condition.
It also returns Boolean value.
Operator
Meaning
&&
Logical AND
||
Logical OR
!
Logical NOT

⏩Logical AND(&&) :-

It returns true if all combined condition are true otherwise returns false.

example:-

  1. 20 >= 20 && 30 > 50 && 4 != 6 ➔ false(0)
  2. 4 != 6 && 4>3 && 4 == 4 ➔ true(1)

⏩Logical OR(||) :-

It returns true if any combined condition is true otherwise returns false.

example:-

  1. 20 >= 20 || 30 > 50 || 4 != 6 ➔ true(1)
  2. 40 != 40 || 40 > 50 ➔ false(0)

⏩Logical NOT(!) :-

It returns true if condition is false otherwise returns false.

example:-

  1. !(40 >50) ➔ true
  2. !(30 > 50 && 4 != 6) ➔ true
  3. !(40 != 60 || 30 > 60) ➔ false

No comments:

Post a Comment