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 :-
- Arithmetic operator
- Relational operator
- Logical operator
- Assignment operator
- Multiple assignment operator
- Compound assignment operator/shortcut assignment
- Increment
- Decrement
- Comma operator
- Sizeof operator
- Bitwise operator
- Unary operator
- Binary operator
- 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:-
- 20 >= 20 && 30 > 50 && 4 != 6 ➔ false(0)
- 4 != 6 && 4>3 && 4 == 4 ➔ true(1)
⏩Logical OR(||) :-
It returns true if any combined condition is true otherwise returns false.
example:-
- 20 >= 20 || 30 > 50 || 4 != 6 ➔ true(1)
- 40 != 40 || 40 > 50 ➔ false(0)
⏩Logical NOT(!) :-
It returns true if condition is false otherwise returns false.
example:-
- !(40 >50) ➔ true
- !(30 > 50 && 4 != 6) ➔ true
- !(40 != 60 || 30 > 60) ➔ false
No comments:
Post a Comment