Local variable: Difference between revisions

Content deleted Content added
mNo edit summary
copyedit for grammar and remove slight POV
Line 1:
In [[computer science]], a '''local variable''' is a [[variable]] that is given ''local [[scope (programming)|scope]]''. Such variablesa arevariable is accessible only from the [[Subroutine|function]] or [[block]] in which it is declared. Local variables are contrasted with [[global variables]].
 
Local variables are special because inIn most languages, theylocal 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 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]] to processes outside of the block in which they are declared.
 
Programming languages that employ ''[[call by value]]'' semantics provide a called subroutine with its own local copy of the [[function argument|arguments]] passed to it. In most languages, these local parameters are treated the same as other local variables within the subroutine. In contrast, ''[[call by reference]]'' and ''[[call by name]]'' semantics allow the parameters to act as aliases of the values passed as arguments, allowing the subroutine to modify variables outside its own scope.