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. In programming languages with only two levels of visibility, local variables are contrasted with global variables. On the other hand, many ALGOL-derived languages allow any number of levels of nested functions with private variables, functions, constants and types hidden within them.

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 distinct addresses. Hence variables of this scope can be declared, written to, and read, without any risk of side-effects to functions 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.

Variables of local scope are used to avoid issues with side-effects that can occur with global variables.

Read more about Local Variable:  Static Local Variables, local in Perl, Local Variables in Ruby

Famous quotes containing the words local and/or variable:

    While it may not heighten our sympathy, wit widens our horizons by its flashes, revealing remote hidden affiliations and drawing laughter from far afield; humor, in contrast, strikes up fellow feeling, and though it does not leap so much across time and space, enriches our insight into the universal in familiar things, lending it a local habitation and a name.
    —Marie Collins Swabey. Comic Laughter, ch. 5, Yale University Press (1961)

    Walked forth to ease my pain
    Along the shore of silver streaming Thames,
    Whose rutty bank, the which his river hems,
    Was painted all with variable flowers,
    Edmund Spenser (1552?–1599)