Answer SL50

PS C:\Source>gcc sumVersion10.c sumDriver10.c
PS C:\Source>a
sum of 1..10: 55
sum of 1..5: 15
PS C:\Source>

Comments: The code compiles and runs and productes the correct sums. The external variable sum is used by both files. The code in one file modifies it and the code in the other file accesses it and prints out its value.

However, this is a poor way to do this. The code violates modularity and is open to bugs. The previous version of the program is much better.

With some compilers this code as is will not compile. With them, the declarations should be:

extern int sum;


Back to Puzzle Home