- Arithmetic Operators
- Relational Operators
- Logical Operators
- Conditional Operators
- Assignment Operators
- Increment and Decrement Operators
- Bitwise Operators
- Special Operators
Arithmetic Operators :
An arithmetic operator plays mathematical operations which include addition, subtraction and multiplication on numerical values (constants and variables).
| Operator | Meaning of Operator |
|---|---|
| + | addition or unary plus (Use when we add two or more then two numbers) |
| - | subtraction or unary minus (Use when we Subtract two or more then two numbers) |
| * | multiplication (Use when we Multiply two or more then two numbers) |
| / | division (Use when we divide two or more then two numbers) |
| % | remainder after division(when we need to find remainder) |
Relational Operators :
A relational operator checks the relationship among operands. If the relation is proper, it returns 1; if the relation is fake, it returns zero.
| Operator | Meaning of Operator | Example |
|---|---|---|
| == | Equal to | When we find both values are equal or not ( a == b returns 0 ) |
| > | Greater than | We use when we check 'a' Greater than 'b' ( a > b returns 1 ) |
| < | Less than | We use when we check 'a' Less than 'b' a < b returns 0 |
| != | Not equal to | We use when we check 4 not equal to 3 ( 4 != 3 returns 1 ) |
| >= | Greater than or equal to | We use when we check 5 Greater than or equal to 3 ( 5 >= 3 returns 1 ) |
| <= | Less than or equal to | We use when we check 5 Less than or equal to 3 ( 5 <= 3 return 0 ) |
Logical Operators :
| && | AND |
| || | OR |
| ! | NOT |
AND ( && )
( Age > 18 && Age < 50 )
In Logical Operator AND (&&) when Both conditions are true then execute the statement.
OR ( || )
( Age > 18 || Age < 50 )
In Logical Operator OR ( || ) when only one or both conditions are true then execute the statement.
NOT ( ! )
( Age > 18 ! Age < 50 )
In Logical Operator NOT ( ! ) first condition must be true and second false then execute the statement.
Conditional Operators :
In Conditional Operator we use ( ? ) and ( :: ) in pair. But how ? see in this line below.
conditional_Expression ? expression1 : expression2
If conditional is true, expression1 is evaluated.
If conditional is false, expression2 is evaluated.
int a=5;
int b=4;
C = ( a > b )? a : b ;
If Conditional_Expression is true then Expression ( a ) will be Evaluate if Conditional_Expression is
false then Expression ( b ) will be evaluate.
So, if Expression ( a ) is true then C= 5 else C=4 . Conditional Operator behave same like if else.
Assignment Operators :
In Program we use Assignment Operator to assign the value in variable or store the result in variable.
Int a = 100;
Here we used Assignment Operator to assign the value in variable ( a ). Assignment Operator assign the right side value in left side.
Increment And Decrement Operators :
Increment And Decrement Operator simply increase or decrease the value. We can use this Operator by two ways Pre Increment And Decrement and Post Increment And Decrement Operator.
Int a = 10;
If we use Increment Operator ( a++ ) then a = 10 and if we use Decrement Operator ( a-- ) then a = 9.
Pre ++a , --a
Post a++, a--
Post a++, a--
int a =100, b;
so a = 101 and b = 100
Post Increment :
b = a++; In this Expression first value of ( a ) assign to ( b ) then Increment Operator applyso a = 101 and b = 100
Pre Increment :
b = ++ a ; In this Expression first Increse the value of ( a ) then assign the value in ( b )so in this case a= 101 and b= 101.
Bitwise Operators :
| & | AND |
| || | OR |
| ^ | Exclusive OR |
| << | left shift |
| >> | right shift |
All through computation, mathematical operations like: addition, subtraction, addition and division are converted to bit-stage which makes processing quicker and saves strength. Bitwise operators are used in C programming to perform bit-level operations.
Special Operators :
Sizeof operator tells how much memory occupy this operand it shows in Byte.
int a = 100;
c= Sizeof (a);
So Sizeof operator return 2 because ( a ) has Integer data types And Integer takes 2 Bytes in memory. We can use Sizeof Operator for finding the size of Array Structure etc.
No comments:
Post a Comment