Puzzle SL2


Rule 2 and Rule 3

What does the following code write to the monitor?

#include <stdio.h>

int main( void )
{
  int a = 1;
  int b = 2;
  
  {
    int b = 3;
    printf("a=%d\tb=%d\n", a, b );
  }
  
  printf("a=%d\tb=%d\n", a, b );
  return 0;
}

This program has a nested scope inside the main scope. At the beginning of that scope is a declaration of a variable, b, which has block scope for that block.



Answer         Next Page         Previous Page Home