View Single Post
  #2   Spotlight this post!  
Unread 23-01-2007, 21:51
Noah Kleinberg Noah Kleinberg is offline
Registered User
FRC #0395 (2TrainRobotics)
Team Role: Driver
 
Join Date: Jan 2006
Rookie Year: 2006
Location: New York
Posts: 196
Noah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to behold
Send a message via AIM to Noah Kleinberg
Re: Why Static Variables?

Quote:
Originally Posted by brianafischer View Post
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...