Puzzle SL40

What does the following write to the monitor?

#include <stdio.h>

static int x = 44;

void foo()
{
  int j = 0, x = 0;

  {
    static int x = 100;
    printf("    inner x: %d\n", x );
    x++ ;
  }

  printf("    outer x: %d\n", x );
}

void main()
{
  int x;

  for ( x=10; x<15; x++ )
  {
    printf("main x: %d\n", x );
    void foo();
  }

}

This puzzle involves a number of scoping rules and linkage rules. As always, try to figure out how many varialbes x there are and where they can be seen.



Answer         Next Page         Previous Page Home