Search: in
Local variable
Local variable Encyclopedia
  Tutorials     Encyclopedia     Dictionary     Directory  
Local_variable Email this to a friend      Local_variable

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.

Static local variables

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 variable. In all of the above languages, 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. The only difference is that they are only accessible through one function. Static locals can also be declared in class-level functions in object-oriented languages.

Stricter and more formal object-oriented languages such as Java and C#, do not allow local variables to be declared static to a function. Instead, "static" variables in these languages are scoped to the class.

Note: This is distinct from other usages of the static keyword, which has several different meanings in various other languages.

fr:Variable locale is:Stašvęr breyta ja:??????





Source: Wikipedia | The above article is available under the GNU FDL. | Edit this article



Related Links in Local variable

Search for Local variable in Tutorials
Search for Local variable in Encyclopedia
Search for Local variable in Dictionary
Search for Local variable in Open Directory
Search for Local variable in Store
Search for Local variable in PriceGig



Help build the largest human-edited directory on the web.
Submit a Site - Open Directory Project - Become an Editor

Advertisement

Advertisement



Local variable
Local_variable top Local_variable

Home - Add TutorGig to Your Site - Disclaimer

©2008-2009 TutorGig.com. All Rights Reserved. Privacy Statement