C Q&A #2: Watch your shift!

What do you this should be the output of the below code? Is there any problem in the code?

#include <stdio.h>

int main(void)
{
  int x = -1, y = 1, a, b, c, d, e, f;

  a = x << 4;
  b = x >> 4;
  c = y << 4;
  d = y >> 4;
  e = y << sizeof (int) * 8;
  f = y << -4;

  printf("a = %x \nb = %x \nc = %x \nd = %x \ne = %x \nf = %x",a, b, c, d, e, f);

  printf ("\n");
  return 0;
}

Continue reading “C Q&A #2: Watch your shift!”