Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Static variable
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{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 [[dynamic memory allocation|dynamically allocated]] objects, whose storage is 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. In general, '''{{visible anchor|static memory allocation}}''' is the allocation of memory at [[compile time]], before the associated program is executed, unlike [[dynamic memory allocation]] or [[automatic memory allocation]] where memory is allocated as required at [[run time (program lifecycle phase)|run time]].<ref>{{cite web | access-date = 2011-06-16 | author = Jack Rons | publisher = MeritHub [An Institute of Career Development] | 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| archive-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 11, 2010}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)