Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

C++ Language/Variables/LifetimeAndScope

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

A variable defined outside of all functions will have "static-lifetime" (it will exist throughout your software's entire duration). A variable defined inside some function could also have static-lifetime, but it would need to be marked by the static keyword. Otherwise, it would be a transient "local-variable" whose storage will disappear when that function ends. A variable defined inside some function has "local-scope" (it can only be used from within that function, regardless of its lifetime). A variable defined outside of all functions has "global-scope" (it can be used by all subsequent functions). If you mark a globally-scoped variable by the static keyword, then it can only be used in this source file. Additional information about lifetime and scope