You may be aware of different operators used in C language.Let's check how these operators actually works, using a C program itself.
#include<stdio.h>
int main()
{
int a,b;
printf("\n Enter Two Numbers \n");
scanf("%d%d",&a,&b);
printf("Unary Operator\n\n");
printf("Increment Operator: %d\n",++a);
printf("Decrement Operator: %d\n\n",--a);
printf("Arithmetic Operators\n\n");
printf("Addition a+b : %d\n",a+b);
printf("subtraction a-b : %d\n",a-b);
printf("multiplication a*b : %d\n",a*b);
printf("division a/b : %d\n",a/b);
printf("modulus a%b : %d\n\n",a%b);
printf("Logical Operators\n\n");
printf("And : %d \n",(a>b)&&1);
printf("or : %d \n",(a>b)||1);
printf("Not : %d \n",!((a>b)||1));
printf("== : %d \n\n",(a>b)==1);
printf("Relational Operators\n\n");
(a>b)?printf("Greatest is : %d \n",a):(a==b)?printf("same\n"):printf("Greatest %d : \n",b);
printf("\n Shift operator\n\n");
printf("Left shift a :%d\n",a<<1);
printf("Right shift a :%d\n\n",a>>1);
iprintf("Bitwise Operators\n\n");
printf("Bitwise And : %d\n ",a&b);
printf("Bitwise Or : %d\n",a|b);
printf("Bitwise Xor : %d\n",a^b);
printf("Bitwise Not : %d \n",!a);
return 0;
}
No comments:
Post a Comment