C Q&A #4: Calling main recursively

What do you think about the following C Code ? What will be the output.

#include <stdio.h>

int main (void)
{
  static int a = 3;

  if (a == 0)
  {
    return 0;
  }

  printf ("going down\n");

  a--;
  main ();

  printf ("coming up\n");

  return 0;
}

Continue reading “C Q&A #4: Calling main recursively”

Advertisements

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!”