Local variable: Difference between revisions

Content deleted Content added
nested blocks and nested functions
Line 1:
In [[computer science]], a '''local variable''' is a [[Variable (programming)|variable]] that is given ''local [[scope (programming)|scope]]''. Such a variable is accessible only from the [[subroutine|function]] or [[block (programming)|block]] in which it is declared. In [[programming language]]s with only two levels of visibility, local variables are contrasted with [[global variables]]. On the other hand, many [[ALGOL]]-derived languages allow any number of nested levels of [[nested function]]svisibility, with private variables, functions, constants and types hidden within them, either by nested blocks or [[nested function]]s.
 
In most languages, local variables are [[automatic variable]]s stored on the [[call stack]] directly. This means that when a [[recursion (computer science)|recursive function]] calls itself, local variables in each instance of the function are given distinct [[Memory address|addresses]]. Hence variables of this scope can be declared, written to, and read, without any risk of [[side-effect (computer science)|side-effects]] to functions outside of the block in which they are declared.