# C Operators Let add operator to our world
An operator is a symbol which performs certain operation on values or variables.
The operators in C can be classified as:
# Arithmetic Operators
An arithmetic operator performs mathematical operations such as addition, subtraction and multiplication on numerical values (constants and variables).
| Operator | Meaning of Operator |
|---|---|
| + | addition |
| - | subtraction |
| * | multiplication |
| / | division |
| % | remainder after division( modulo division) |
Below program demonstrate the use of arithmetic operator :
# Increment and decrement Operator
| Operator | Meaning of Operator |
|---|---|
| Increment ++ | increases the value by 1 |
| Decrement -- | decreases the value by 1 |
Below program demonstrate the use of Increment and decrement Operator :
# Assignment Operators
An assignment operator is used for assigning a value to a variable. The most common assignment operator is =
| Operator | Example | Same as |
|---|---|---|
| = | a = b | a =b |
| += | a += b | a = a+b |
| -= | a -= b | a = a-b |
| *= | a *= b | a = a*b |
| %= | a %= b | a = a%b |
Below program demonstrate the use of Assignment Operators :
# Relational(or logical) Operators
A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0.
Relational operators are used in decision making and loops (We will read in next chapter).
| Operator | Description | Example |
|---|---|---|
| == | Checks if the value of two operands is equal or not, if yes then condition becomes true. | (A == B) is not true. |
| != | Checks if the value of two operands is equal or not, if values are not equal then condition becomes true. | (A != B) is true. |
| > | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. | (A > B) is not true. |
| < | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. | (A < B) is true. |
| >= | 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) is not true. |
| <= | 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) is true. |
| && | Called Logical AND operator. If both the operands are non zero then then condition becomes true. | (A && B) is true. |
| || | Called Logical OR Operator. If any of the two operands is non zero then then condition becomes true. | (A || B) is true. |
| ! | 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) is false. |
Below program demonstrate the use of Relational Operators :
Below program demonstrate the use of logical Operators :
TASKS
- Ask two number from user and calculate their Quotient and Remainder.
← C Input C Branching →