Variable

From Mario Fan Games Galaxy Wiki
Revision as of 06:05, 5 January 2009 by Xgoff (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A variable is a memory address that holds some sort of value (like ones used in algebra), and is usually named. The exact syntax for describing a variable differs by language, with higher-level languages such as scripting languages having a less verbose syntax.

Generally, most languages allow at least values and strings to be stored in a variable, but others allow more datatypes such as functions to be stored in this manner. Not all variables can be accessed at any time or from any location; these limitations are defined by the variable's scope. The following is a list of various types and scopes of a variable:

Scope

  • Global: A global variable's scope is usually unlimited; global variables can usually be accessed from any function at any time. It is considered bad programming practice to overuse global variables as there is a higher risk of name collisions.
  • Local: Local variables can only be accessed from the block in which they are defined; some languages may or may not expand the scope to cover nested blocks or similar constructs. Local variables only last for a limited time; they and their contents are destroyed once the block in which they reside has run.