E27 Answer


x before foo: 444
x as parameter: 7
x as parameter: 25
x after  foo: 444

Comments: The linker creates and initializes external variables when it creates the executable file. As in the previous puzzle, there is just one external variable x in this project, which is initialized to 444 before execution begins.

When foo() executes, it changes its parameter x. But this x has no linkage and is a different x than the external one. It also has block scope, which hides the other x in fileB.c in that scope.


/* --- fileB.c --- */
int x = 444 ;
foo(int x)
{
  printf("x as parameter: %d\n", x );
  x = 25;
  printf("x as parameter: %d\n", x );
}



/* --- fileC.c --- */ main() { extern int x ; printf("x before foo: %d\n", x ); foo( 7 ); printf("x after foo: %d\n", x ); system("pause"); }