C- Operators
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 −
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Misc Operators
Arithmetic Operators
+
|
Adds two operands.
|
−
|
Subtracts second operand from the first.
|
*
|
Multiplies both operands.
|
/
|
Divides numerator by de-numerator.
|
%
|
Modulus Operator and remainder of after an integer division.
|
++
|
Increment operator increases the integer value by one.
|
--
|
Decrement operator decreases the integer value by one.
|
Rational Operators
==
|
Checks if the values of two operands are equal or not. If yes, then the condition becomes true.
|
!=
|
Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true.
|
>
|
Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true.
|
<
|
Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true.
|
>=
|
Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true.
|
<=
|
Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true.
|
Logical Operators
&&
|
Called
Logical AND operator. If both the operands are non-zero,
then the condition
becomes true.
|
||
|
Called
Logical OR Operator. If any of the two operands is non-zero,
then the
condition becomes true.
|
!
|
Called
Logical NOT Operator. It is used to reverse the logical state of its operand.
If a condition is true, then Logical NOT operator will make it false.
|
Bitwise Operators
&
|
Binary
AND Operator copies a bit to the result if it exists in both operands.
|
|
|
Binary
OR Operator copies a bit if it exists in either operand.
|
^
|
Binary
XOR Operator copies the bit if it is set in one operand but not both.
|
~
|
Binary
Ones Complement Operator is unary and has the effect of 'flipping' bits.
|
<<
|
Binary
Left Shift Operator. The left operands value is moved left by the number of
bits specified by the right operand.
|
>>
|
Binary
Right Shift Operator. The left operands value is moved right by the number of
bits specified by the right operand.
|
Assignment Operators
=
|
Simple
assignment operator. Assigns values from right side operands to left side
operand
|
+=
|
Add
AND assignment operator. It adds the right operand to the left operand and
assign the result to the left operand.
|
-=
|
Subtract
AND assignment operator. It subtracts the right operand from the left operand
and assigns the result to the left operand.
|
*=
|
Multiply
AND assignment operator. It multiplies the right operand with the left
operand and assigns the result to the left operand.
|
/=
|
Divide
AND assignment operator. It divides the left operand with the right operand
and assigns the result to the left operand.
|
%=
|
Modulus
AND assignment operator. It takes modulus using two operands and assigns the
result to the left operand.
|
<<=
|
Left
shift AND assignment operator.
|
>>=
|
Right
shift AND assignment operator.
|
&=
|
Bitwise
AND assignment operator.
|
^=
|
Bitwise
exclusive OR and assignment operator.
|
|=
|
Bitwise
inclusive OR and assignment operator.
|
Misc Operators
sizeof()
|
Returns
the size of a variable.
|
&
|
Returns
the address of a variable.
|
*
|
Pointer
to a variable.
|
Comments
Post a Comment