E15 Answer


scope g: a=1    b=2     g=3

#include <stdio.h>
int g( int a, int b )
{
  int g=3 ;
  printf("scope g: a=%d    b=%d   g=%d\n", a, b, g );
}

int main ( void )
{
  g( 1, 2 ) ;
  system("pause") ;
  return 0 ;
}

Comments: The program compiles and runs. The identifier g is first defined as a function. This definition has file scope, which enables it to be used when the main menthod calls function g. The body of the function (a block) defines a variable, g. This variable has block scope, and hides the definition of the function of the same name.

So the function could not call itself, and the g in the printf() refers to the variable.

Although syntactically correct, it is unwise to have a variable and a function share a name.