A Global Variable is accessible by all functions in the program. This means that it may be changed anywhere in the program by mistake. If you have a large program (especially one that several porgrammers are working on) global variables can cause a lot of problems.
Local variables are visible only within the function in which they are created and cease to exist once the program returns from the function.
It is much safer to pass variables into functions as parameters. The parameters passed in have the same scope as local variables within the function. This way a much tighter control over the use of variables exists and mistakes are fewer. It is also much easier to debug a program if you have a tight control over which functions use any particular variable.
Alan
|