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.
A special type of local variable is available in some languages, such as Visual Basic.NET or 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.