Information about Local Variable

In computer science, a local variable is a variable that is given local scope. Such variables are accessible only from the function or block in which it is declared. Local variables are contrasted with global variables.

Local variables are special because in most languages they 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

Main article: Static variable
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.
Computer science, or computing science, is the study of the theoretical foundations of information and computation and their implementation and application in computer systems.
..... Click the link for more information.
variable (IPA pronunciation: [ˈvæɹiəbl]) (sometimes called a pronumeral) is a symbolic representation denoting a quantity or expression.
..... Click the link for more information.
In computer programming, scope is an enclosing context where values and expressions are associated. Various programming languages have various types of scopes. The type of scope determines what kind of entities it can contain and how it affects them -- or semantics.
..... Click the link for more information.
In computer science, a subroutine (function, method, procedure, or subprogram) is a portion of code within a larger program, which performs a specific task and can be relatively independent of the remaining code.
..... Click the link for more information.
Block may refer to:

Objects that resemble rectangular prisms:
  • A large concrete or stone brick
  • Block (sailing), a single or multiple pulley used on sailboats
  • Cylinder block, the main part of an internal combustion engine

..... Click the link for more information.
In computer programming, a global variable is a variable that is accessible in every scope. Interaction mechanism with global variables are called global environment (see also global state) mechanisms.
..... Click the link for more information.

..... Click the link for more information.
In computer science, a call stack is a special stack which stores information about the active subroutines of a computer program. (The active subroutines are those which have been called but have not yet completed execution by returning.
..... Click the link for more information.
Recursion in computer programming defines a function in terms of itself. One example application of recursion is in recursive descent parsers for programming languages. The great advantage of recursion is that an infinite set of possible sentences, designs, or other data can be
..... Click the link for more information.
In computing, an address space defines a range of discrete addresses, each of which may correspond to a physical or virtual memory register, a network host, peripheral device, disk sector or other logical or physical entity.
..... Click the link for more information.
side effect if it modifies some state in addition to returning a value. For example, a function might modify a global or a static variable, modify one of its arguments, write data to a display or file, or read some data from other side-effecting functions.
..... Click the link for more information.
evaluation strategy is a set of (usually deterministic) rules for determining the evaluation of expressions in a programming language. Emphasis is typically placed on functions or operators — an evaluation strategy defines when and in what order the arguments to a function
..... Click the link for more information.
In computer programming, a parameter is a variable which takes on the meaning of a corresponding argument passed in a call to a subroutine. In the most common case, call-by-value, a parameter acts within the subroutine as a local (isolated) copy of the argument, but in other
..... Click the link for more information.
evaluation strategy is a set of (usually deterministic) rules for determining the evaluation of expressions in a programming language. Emphasis is typically placed on functions or operators — an evaluation strategy defines when and in what order the arguments to a function
..... Click the link for more information.
side effect if it modifies some state in addition to returning a value. For example, a function might modify a global or a static variable, modify one of its arguments, write data to a display or file, or read some data from other side-effecting functions.
..... Click the link for more information.
static variables typically have a broader scope than other variables. Their values may be set at run-time or may change subtly during program execution.

For constants


..... Click the link for more information.
C

The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language.
..... Click the link for more information.
C++
Paradigm: Multi-paradigm
Appeared in: 1983
Designed by: Bjarne Stroustrup
Typing discipline: Static, unsafe, nominative
Major implementations: G++, Microsoft Visual C++, Borland C++ Builder
Dialects: ISO/IEC C++ 1998, ISO/IEC C++ 2003
..... Click the link for more information.
Visual Basic

Paradigm: Event-driven
Developer: Microsoft
Typing discipline: Static, strong
Influenced by: QuickBASIC
Influenced: Visual Basic .NET
OS: Microsoft Windows

Visual Basic (VB
..... Click the link for more information.
' Visual Basic .NET

Paradigm: structured, imperative, object-oriented
Appeared in: 2001 (last revised 2005)
Designed by: Microsoft Corporation
Typing discipline: dynamic, strong, both safe and unsafe[1], nominative
Major implementations: .
..... Click the link for more information.
Object-oriented programming (OOP) is a programming paradigm that uses "objects" and their interactions to design applications and computer programs. It is based on several techniques, including inheritance, modularity, polymorphism, and encapsulation.
..... Click the link for more information.
Object-oriented programming (OOP) is a programming paradigm that uses "objects" and their interactions to design applications and computer programs. It is based on several techniques, including inheritance, modularity, polymorphism, and encapsulation.
..... Click the link for more information.
Java

Paradigm: Object-oriented, structured, imperative
Appeared in: 1995
Designed by: Sun Microsystems
Typing discipline: Static, strong, safe, nominative
Major implementations: Numerous
Influenced by: Objective-C, C++, Smalltalk, Eiffel,[1]
..... Click the link for more information.
C#
Paradigm: structured, imperative, object-oriented
Appeared in: 2001 (last revised 2005)
Designed by: Microsoft Corporation
Typing discipline: static, strong, both safe and unsafe, nominative
Major implementations: .NET Framework, Mono, DotGNU
Dialects: 1.
..... Click the link for more information.


This article is copied from an article on Wikipedia.org - the free encyclopedia created and edited by online user community. The text was not checked or edited by anyone on our staff. Although the vast majority of the wikipedia encyclopedia articles provide accurate and timely information please do not assume the accuracy of any particular article. This article is distributed under the terms of GNU Free Documentation License.
Herod_Archelaus


page counter