Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
compare webbrowser
Freenet DSL
Who's Online
3 user(s) are online (3 user(s) are browsing encyclopedia)

Members: 0
Guests: 3

more...
browser tip
Unix Befehle
manual of unix befehle
recommendation!
Sponsored
partner

Local variable

In computer science, a local variable is a Variable that is given local Scope (computer science) . 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-effect (computer science).

Some advocate that all variables should be of local scope to avoid issues with Side-effect (computer science). In other cases, programming paradigms and languages themselves, such as the functional programming paradigm and the Haskell programming language language require all variables (or the closest equivalent under that paradigm to variables) to be of local scope, and the functionality of the program is achieved only by passing local variables from one function to another.

=Static local variables=

A special type of local variable, called a static local, is available in many mainstream languages, including C programming language/C plus plus, Visual Basic and Visual Basic .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 the static keyword.

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 the above Object-oriented programming languages, and the behaviour differs depending on the language: *In C plus plus, static locals declared in class-level functions are shared across all objects. That is, they act like static class-level variables. *In Visual Basic and Visual Basic .NET, static locals declared in class-level functions are local to the object. That is, they act like non-static class-level variables, and each object has its own copy of the variable.

Stricter and more formal Object-oriented programming languages such as Java programming language and C Sharp, do not allow local variables to be declared static at all.

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