E13 Answer


scope f: a=1    b=2     g=3
scope g: g=3.140000
scope m: a=77   b=99    g=777

#include <stdio.h>
int g = 777;

int glue( double g )
{
  printf("scope g: g=%lf\n", g );
}

int funct( int a, int b )
{
  int g=3 ;
  printf("scope f: a=%d   b=%d   g=%d\n", a, b, g );
}

int main ( void )
{
  int a=77, b=99 ;
  
  funct( 1, 2 ) ;
  glue ( 3.14 );
  printf("scope m: a=%d   b=%d   g=%d \n", a, b, g ) ;

  system("pause") ;
  return 0 ;
}

Comments:

In this program, the identifier g is defined in several places. Its first definition gives the variable g file scope. This means it can be used anywhere in the file unless hidden by another declaration.

The first place the file-scope variable is hidden is when function glue() declares a parameter g. Now, in the body of that function, the identifier g refers to the parameter.

The second place the file-scope variable is hidden is in the function funct() where a local variable g is declared inside a block. Now, in that block, the identifier g refers to that variable.