Answer SL24


99 

Comments: This is logically identical to the previous puzzle. The extern declarations of x in fileC.c was not needed. There is just one object x, which is referred to in all three files. The object x is initialized to 8, but then the call to foo() changes it to 99.

However: Some C compilers require extern declarations for all external variables.


/* --- fileA.c --- */
int x = 8;

/* --- fileB.c --- */
void foo()
{
  extern int x;
  x = 99;
}

/* --- fileC.c --- */
#include <stdio.h>
void foo();

int x;
void main()
{
  foo();
  printf("%d\n", x );
}



Back to Puzzle Home