Jump to content

Local variable

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MattGiuca (talk | contribs) at 10:19, 10 April 2005 (New article). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

In computer science, a local variable is a variable that is given local scope. Such variables are accessible only from the function or block in which it is declared.

Local variables are special because in most languages they are stored on the function stack directly. This means that when a recursive function calls itself, local variables in each instance of the function are given separate memory address space. Hence variables of this scope can be declared, written to, and read, without any risk of side-effects.

Some programming paradigms and languages, such as functional programming (and its languages such as Haskell) require all variables to be of local scope, and the functionality of the program is achieved only by passing local variables from one function to another.