(computer science) A variable which can be accessed (used or changed) only in one block of a computer program.
| Sci-Tech Dictionary: local variable |
(computer science) A variable which can be accessed (used or changed) only in one block of a computer program.
| Computer Desktop Encyclopedia: local variable |
In programming, a variable used only within the routine or function it is defined in. When the function is finished and control is returned back to the part of the program that called it, the local variables no longer exist. Contrast with global variable.
Download Computer Desktop Encyclopedia to your iPhone/iTouch
| Wikipedia: Local variable |
In computer science, a local variable is a variable that is given local scope. Such a variable is accessible only from the function or block in which it is declared. Local variables are contrasted with global variables.
In most languages, local variables are automatic variables stored on the call 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 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 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.
Some advocate that all variables should be of local scope to avoid issues with side-effects.
A special type of local variable, called a static local, is available in many mainstream languages (including C/C++, Visual Basic, and VB.NET) which allows a value to be retained from one call of the function to another. In this case, recursive calls to the function also have access to the (single, statically allocated) variable. In all of the above languages, static variables are declared as such with a special storage class keyword (e.g., static).
Static locals in global functions can be thought of as global variables, because their value remains in memory for the life of the program.[1] The only difference is that they are only accessible (i.e., scoped) to one function.
This is distinct from other usages of the static keyword, which has several different meanings in various languages.
local in PerlPerl has a keyword, local, for “localizing” variables, but in this case, local isn't what most people think of as “local”.[2] It gives a temporary, dynamically-scoped value to a global (package) variable, which lasts until the end of the enclosing block. However, the variable is visible to any function called from within the block.[3]
To create lexical variables, which are more like the automatic variables discussed above, use the my operator instead.[4]
local()my()This entry is from Wikipedia, the leading user-contributed encyclopedia. It may not have been reviewed by professional editors (see full disclaimer)
| static variable (computer science) | |
| global variable (technology) | |
| hidden-variable theory of the second kind (quantum mechanics) |
Copyrights:
![]() | Sci-Tech Dictionary. McGraw-Hill Dictionary of Scientific and Technical Terms. Copyright © 2003, 1994, 1989, 1984, 1978, 1976, 1974 by McGraw-Hill Companies, Inc. All rights reserved. Read more | |
![]() | Computer Desktop Encyclopedia. THIS COPYRIGHTED DEFINITION IS FOR PERSONAL USE ONLY. All other reproduction is strictly prohibited without permission from the publisher. © 1981-2009 Computer Language Company Inc. All rights reserved. Read more | |
![]() | Wikipedia. This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "Local variable". Read more |
Mentioned in