Advertisement
Shailrshah

Operators

Apr 18th, 2013
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.67 KB | None | 0 0
  1. #include <stdio.h>
  2. int main(){
  3.     int a = 3, b = 5, c = -3;
  4.     printf("a = %d, b = %d, c = %d\n",a,b,c);
  5.     printf("Bitwise AND operation of a and c gives %d \n", a & c);
  6.     printf("Bitwise OR operation of b and c gives %d \n",b | c);
  7.     printf("Bitwise EXOR operation of a and b gives %d \n",a ^ b);
  8.     printf("3 Bitwise left shifts of c gives %d \n",c << 3);
  9.     printf("4 Bitwise right shifts of a gives %d \n",a >> 4);
  10.     printf("The result of the addition of pre-incremented c and pre-incremented a is %d \n",++c + --a);
  11.     printf("The result of adding 1 to pre-decremented b is %d \n",--b + 1);
  12.     printf("The result of a*b - c/b is %d \n",a *b  - c / b);
  13.     printf("Logical AND and OR of (a<b) and (b<c) is %d and ",(a < b) && (b < c));
  14.     printf(" %d\n ",(a < b) || (b < c));
  15.     printf("Using '+=10', the value of a has been changed to %d \n",a += 10);
  16.     printf("Using '*=c', the value of b has been changed to %d \n",b *= c);
  17.     printf("Using '/=b', the value of c has been changed to %d \n",c /= b);
  18.     printf("Using unary minus, the b is now is %d\n", b = -b);
  19. }
  20. //Output
  21. //a = 3, b = 5, c = -3
  22. //Bitwise AND operation of a and c gives 1
  23. //Bitwise OR operation of b and c gives -3
  24. //Bitwise EXOR operation of a and b gives 6
  25. //Bitwise left shift of c gives -24
  26. //Bitwise right shift of a gives 0
  27. //The result of the addition of pre-incremented c and pre-incremented a is 0
  28. //The result of adding 1 to pre-decremented b is 5
  29. //The result of a*b - c/b is 8
  30. //Logical AND and OR reuslt is 0  1
  31. //Using '+=', the value of a has been changed to 12
  32. //Using '*=', the value of b has been changed to -8
  33. //Using '/=', the value of c has been changed to 0
  34. //Using unary minus, the b is now is 8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement