Quote:
Originally Posted by brianafischer
I am trying to create a list of "good" programming practices for the students. I cannot seem to google a good reason for proper use of static variables instead of globals. Anyone interested in sharing some knowledge?
When is a static variable required over a global?
What are the advantages of static variables?
What are the disadvantages of static variables?
Thanks!
|
There might be something that I'm forgetting, but I believe that the only advantage of static variables over globals is that a static variable is self-explanatory in the fact that it will only be used in that function. A global variable could be changed in other functions and someone reading your code would not know whether or not it is. If you are familiar with classes (in C++ for example), this is basically the same advantage as using private variables over public variables. I hope this was helpful, and good luck...