👉Operator
It is a special symbol which is used to perform logical or mathematical operation on data or variable.
👉Operand
It is a data or variable on which the operation is to be performed.
👉Types of Operator
⇒Arithmetic Operators
⇒Relational Operators
⇒Logical Operators
⇒Assignment Operators
⇒Bitwise Operators
⇒Increment/Decrement Operators
⇒Conditional Operators
⇒Special Operator
👉Arithmetic Operators
Symbol | Operation | Example |
+ | Addition | x+y |
- | Subtraction | x-y |
* | Multiplication | x*y |
/ | Division | x/y |
% | Modulus | x%y |
#include<stdio.h> int main() { int x=16,y=3;//For operation int add,sub,multi,div,mod;//To store the result add=x+y; sub=x-y; multi=x*y div=x/y; mod=x%y; printf("Addition=%d\n",add); printf("Subtraction=%d\n",sub); printf("Multiplication=%d\n",multi); printf("Division=%d\n",div); printf("Modulus=%d\n",mod); } ### Output ### Addition=19 Subtraction=13 Multiplication=48 Division=5 Modulus=1 //because % stores remainder
👉Relational Operators
Symbol | Operation | Example |
== | Equal to | 2==3 returns 0 |
!= | Not equal to | 2!=3 returns 1 |
> | Greater than | 2>3 returns 0 |
< | Less than | 2<3 returns 1 |
>= | Greater than or equal to | 2>=3 returns 0 |
<= | Less than or equal to | 2<=3 returns 1 |
👉Logical Operators
(x>y)&&(x>z) | Here this expression returns true if both conditions are true. |
(x>y)||(x>z) | Here this expression returns true if any one or both conditions are true. |
!(x>y) | Not operator reverses the state means if the condition is true it returns false and if the condition is false it returns true. |
#include<stdio.h> int main() { int a=10,b=50,c=30; if(a>b&&a>c) printf("a is greatest"); if(b>a&&b>c) printf("b is greatest"); if(c>a&&c>b) printf("c is greatest"); } /* ### Output ### b is greatest */
👉Assignment Operators
Symbol | Example | Same as |
= | x=y | x=y |
+= | x+=y | x=x+y |
-= | x-=y | x=x-y |
*= | x*=y | x=x*y |
/= | x/=y | x=x/y |
%= | x%=y | x=x%y |
#include<stdio.h> int main() { int x1=5,y1=3; x1+=y1; //x1=x1+y1 printf("x1=%d\n",x1); int x2=5,y2=3; x2-=y2; //x2=x2-y2 printf("x2=%d\n",x2); int x3=5,y3=3; x3*=y3; //x3=x3*y3 printf("x3=%d\n",x3); int x4=5,y4=3; x4/=y4; //x4=x4/y4 printf("x4=%d\n",x4); int x5=5,y5=3; x5%=y5; //x5=x5%y5 printf("x5=%d\n",x5); } ### Output ### x1=8 x2=2 x3=15 x4=1 x5=2
👉Bitwise Operators
Symbol | Operation | Example |
& | Bitwise AND | x&y |
| | Bitwise OR | x|y |
<< | Shift Left | x<<2 |
>> | Shift Right | x>>2 |
#include<stdio.h> int main() { int a=5,b=3,c;//variable declaration c=a&b; // AND operation printf("a&b=%d\n",c); c=a|b; // OR operation printf("a|b=%d\n",c); c=a>>2; // shift right operation printf("a>>2=%d\n",c); c=a<<2; // shift left operation printf("a<<2=%d\n",c); } /* ### output ### a&b=1 a|b=7 a>>2=1 a<<2=20 */
👉Increment/Decrement Operators
Symbol | Name | Function | Example |
++ | Increment | It increments the value by 1 | ++x |
-- | Decrement | It decrements the value by 1 | --x |
#include<stdio.h> int main() { int x=3,y=2; printf("%d\n",++x); printf("%d",--y); } ### Output ### 4 1
👉Conditional Operators
#include<stdio.h> int main() { 5<2?printf("Hello"):printf("Hi"); } ### Output ### Hi//because condition is false
👉Special Operators
Symbol | Description | Example |
& | It is used find address of a variable | int a=10; printf("%d",&a); |
* | It is used to declare pointer type variable. | int *p; |
sizeof() | It returns the memory size of variable. | int a=10; printf("%d",sizeof(a)); |
Request:-If you found this post helpful then let me know by your comment and share it with your friend.
If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all.
If you have not subscribed my website then please subscribe my website.
Try to learn something new and teach something new to other.
Thanks.
0 Comments