Local variable: Difference between revisions

Content deleted Content added
recat
Static Variable
Line 2:
 
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-effect (computer science)|side-effects]].
 
A special type of local variable is available in some languages, such as [[Visual Basic#Visual Basic and VB.NET|Visual Basic.NET]] or [[C Sharp|C#]] which allows a value to be retained from one call of the function to another. The value is only lost when the object containing the variable is destroyed. In this case, recursive calls to the function also have access to the variable. One name for this type of variable is a ''static variable''.
 
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.