views:

294

answers:

3

What are static variables designed for? What's the difference between static int and int?

+2  A: 

A static member can be referenced without an instance.

See the "Static Members" section here: http://www.cplusplus.com/doc/tutorial/classes2/

Matt
The question, though, was about static variables, not members.
Michael Krelin - hacker
It's not clear the OP was making that distinction, even though 'variable' was the term used.
Roger Pate
@Michael: Which could mean static member variable (it depends what the original question is about and it is not 100% clear).
Martin York
Martin, yes, it could, but I'd want more evidence before narrowing it down. And just in case - if there were downvotes, then not mine - I only thought the answer deserves comment ;-)
Michael Krelin - hacker
+3  A: 

Static variables are initialized in the data segment (on x86; modify as appropriate for other architectures) instead of on the stack. They persist for the life of the program instead of vaporizing once they go out of scope.

Ignacio Vazquez-Abrams
It's not clear, but you seem to be mixing two different meanings of static into one definition.
Martin York
+28  A: 
Roger Pate