Puzzle SL5


What does the following code write to the monitor?

#include <stdio.h>
int main( void )
{
  int a = 1;
  int b = 2;
  printf("scope m: a=%d\tb=%d\n", a, b );
  
  {
    int b = 3;
    printf("scope 1: a=%d\tb=%d\n", a, b );
    
    {
      int b = 4;
      printf("scope 2: a=%d\tb=%d\n", a, b );
    }

    printf("scope 1: a=%d\tb=%d\n", a, b );
  }
  
  printf("scope m: a=%d\tb=%d\n", a, b );
  return 0;
}

There are now three separate variables, each named b, declared in three nested blocks.



Previous Page        Answer         Next Page         Home