The operators are used to control/operate the various types of expressions within any program of the 'C' language.
In 'C' language,there are five types of operators:Arithmetical Operators
- "+" : for addition
- "-" : for subtraction
- "*" : for multiplication
- "/" : for division
- "%": for modulation(to obtain the remainder).
Ex: 5/2 = 2.5 , 6/2 = 3 , 5%2 = 1 , 6%2 = 0.
Logical Operators
- "&&" : AND(Double Ampersand)
- "||" : OR(Double Pipe)
- "!" : NOT(Exclamation).
Relational Operators
- ">" : is greater than
- ">=" : is greater than or equal to
- "<" : is less than
- "<=" : is less than or equal to
- "==" : is equal to
- "!=" : is not equal to.
Assignmental Operators
"=" : equals or equal to.Ex: a = 5 ('5' is assigned to variable 'a') , while in a == 5 ('a' is compared with '5').
NOTE:Logical operators are never used independently , thy are used in combination with Relational Operators.
Short-Hand Operators
These operators are very useful as they decrease the time consumption.That's why they are known as Short-Hand Operators.- "++" : incremental operator(increase by '1')
- "--" : decremental operator(decrease by '1')
- "+=" : increment by '1' or any real value
- "-=" : decrement by '1' or any real value
- "*=" : multiply by any value
- "/=" : divide by any value.
Ex: 1. k = k + 1 OR k++
2. k = k - 1 OR k--
3. k = k + 2 OR k+=2
4. k = k - 2 OR k-=2
5. k = k * 3 OR k*=36. k = k / 3 OR k/=3.
No comments:
Post a Comment