Static variable: Difference between revisions

Content deleted Content added
No edit summary
GreenC bot (talk | contribs)
 
(One intermediate revision by one other user not shown)
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.
Line 11:
| title = What is static memory allocation and dynamic memory allocation?
| quote = The compiler allocates required memory space for a declared variable. By using the addressof operator, the reserved address is obtained and this address may be assigned to a pointer variable. Since most of the declared variables have static memory, this way of assigning pointer value to a pointer variable is known as static memory allocation. Memory is assigned during compilation time.
| url = http://www.merithub.com/q/58-static-memory-allocation-dynamic-memory-allocation.aspx}}{{Dead| linkarchive-url = https://web.archive.org/web/20100611071852/http://www.merithub.com/q/58-static-memory-allocation-dynamic-memory-allocation.aspx| url-status = dead| archive-date = June 202311, 2010}}</ref>
 
==History==