Shift Operators

Q

What will be printed as the result of the operation below:

          main() {
              int x=5;
             
printf("%d,%d,%d\n",x,x<<2,x>>2);
          }

✍: FYIcenter

A

As x = 5 = 0x0000,0101; so x << 2 -< 0x0001,0100 = 20; x >> 2 -> 0x0000,0001 = 1. Therefore, the answer is 5, 20, 1.

2007-02-26, 6923👍, 0💬