|
+, -, *, /, % |
|
<, <=, >, >= |
|
==, != |
|
&&, ||, ! |
|
= |
|
-, ++, –, sizeof |
|
&, |, ^, ~, <<, >> |
|
? : |
Example:- int money; /* Here we don’t know exact value of variable ‘money’ */ money = 10; /* Using assignment operator we assign 10, now value of ‘money’ is 10*/ |
We wiil see below some example of arithmetic operators
4 + 5 = 9; 5 – 4 = 1; 5 * 4 = 20; 20 / 4 = 5; 21 / 4 = 5; 25 / 6 = 4; 20 % 4 = 0; 21 % 4 = 1; 25 % 10 = 5; Remember modulus( % ) operator always gives remainder. |
Use of unary operators.
Use of increment ( ++ ) operator a++; (This is called post increment, the value of a is incremented by one after executing this statment) ++a; (This is called pre increment, the value of a is incremented by one before executing this statment)Use of decrement ( — ) operator a–; (This is called post decrement, the value of a is decremented by one after executing this statment) –a; (This is called pre decrement, the value of a is decremented by one before executing this statment)sizeof operator is used to calculate the size of datatypes in number of bytes, sizeof can be applied to all datatypes.Note :- if you did not understand, no need to worry as we will use these operators in C program things will be more cleared. |
Here I would like to explain bit wise operator in little detail because these are most useful operators in C.
& – Bitwise AND
| – Bitwise OR
^ – Bitwise EX-OR
~ – one’s complement
Bitwsie AND
a b a&b 0 0 0 |
Bitwise OR
a b a|b |
Bitwise EX-OR
a b a^b |
Bitwise operators performs on one or more bit patterns or binary numerals levels of their indivisual bits.
Example :- 3 & 5 = 1 /*Here we do AND operation on bit representation of 3 and 4. */ 3 -> 0011 & 4-> 0101 1-> 0001 |