Static variable: Difference between revisions

Content deleted Content added
No edit summary
Not all objects are allocated in the heap.
Line 1:
{{short description|Programming variable that persists for the lifetime of the program}}
{{see also|Static (keyword)}}
In [[computer programming]], a '''static variable''' is a [[variable (programming)|variable]] that has been [[memory allocation|allocated]] "statically", meaning that its [[variable lifetime|lifetime]] (or "extent") is the entire run of the program. This is in contrast to shorter-lived [[automatic variable]]s, whose storage is [[stack allocation|stack allocated]] and deallocated on the [[call stack]]; and in contrast to [[Objectdynamic (computermemory science)allocation|objectsdynamically allocated]] objects, whose storage is [[dynamic memory allocation|dynamically allocated]] and deallocated in [[heap memory]].
 
[[Variable lifetime]] is contrasted with [[Scope (computer science)|scope]] (where a variable can be used): "global" and "local" refer to scope, not lifetime, but scope often implies lifetime. In many languages, [[global variable]]s are always static, but in some languages they are dynamic, while [[local variable]]s are generally automatic, but may be static.