C Tutorials
| Operators |
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assigment Operator
6. Misc Operators
| Arithmetic Operators |
Operator |
Description |
Example |
|---|---|---|
+ |
Addition |
a+b |
- |
Subtraction |
a-b |
* |
Mulitplication |
a*b |
/ |
Division |
a/b |
% |
Modulus |
a%b |
++ |
Increment Operator |
++a, a++ |
-- |
Decrement Operator |
--a, a-- |
| Relational Operators |
Operator |
Description |
Example |
|---|---|---|
== |
Checks if the value of two operands is equal or not, if yes then condition becomes true. | a==b |
!= |
Checks if the value of two operands is equal or not, if values are not equal then condition becomes true. | a!=b |
> |
Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. | a>b |
< |
Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. | a<b |
>= |
Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. | a>=b |
<= |
Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. | a<=b |
| Logical Operators |
Operator |
Description |
Example |
|---|---|---|
&& |
Called Logical AND operator. If both the operands are non zero then condition becomes true. |
a&&b |
|| |
Called Logical OR Operator. If any of the two operands is non zero then condition becomes true. |
a||b |
! |
Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. |
!(a&&b) |
| Bitwise Operators |
Operator |
Description |
Example |
|---|---|---|
& |
Binary AND Operator copies a bit to the result if it exists in both operands. |
a&b |
| |
Binary OR Operator copies a bit if it exists in either operand. |
a|b |
^ |
Binary XOR Operator copies the bit if it is set in one operand but not both. |
a ^ b |
~ |
Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. |
~ a |
<< |
Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. |
a << 2 |
>> |
Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. | a >> 2 |
| Assignment Operators |
Operator |
Description |
Example |
|---|---|---|
= |
Simple assignment operator, Assigns values from right side operands to left side operand | a=5 |
| Misc Operators |
Operator |
Description |
Example |
|---|---|---|
sizeof() |
Returns the size of an variable. |
sizeof(a) |
& |
Returns the address of an variable. |
&a; |
* |
Pointer to a variable. |
*a; |
? : |
Conditional Expression |
If a>b? a:b; |
No comments:
Post a Comment