In computer programming, a variable is an abstract storage location paired with an associated symbolic name, which contains some known or unknown quantity of data or object referred to as a value; or in simpler terms, a variable is a named container for a particular set of bits or type of data (like integer, float, string, etc...).
The value of a computing variable is not necessarily part of an equation or formula as in mathematics.
A variable's storage location may be referenced by several different identifiers, a situation known as aliasing.
Compilers have to replace variables' symbolic names with the actual locations of the data.
In imperative programming languages, values can generally be accessed or changed at any time.
In pure functional and logic languages, variables are bound to expressions and keep a single value during their entire lifetime due to the requirements of referential transparency.
Alternatively, a datatype may be associated only with the current value, allowing a single variable to store anything supported by the programming language.
Most languages define a specific scope for each variable (as well as any other named entity), which may differ within a given program.
Alternatively, a variable with dynamic scope is resolved at run-time, based on a global binding stack that depends on the specific control flow.
The extent of the binding is the portion of the program's execution time during which the variable continues to refer to the same value or memory location.
A running program may enter and leave a given extent many times, as in the case of a closure.
A variable whose extent ends before its scope may become a dangling pointer and deemed uninitialized once more since its value has been destroyed.
To avoid wasting such space, compilers often warn programmers if a variable is declared but not used.
Many programming languages employ a reserved value (often named null or nil) to indicate an invalid or uninitialized variable.
For example, a variable of type "integer" is prohibited from storing text values.
For instance, in this Python code segment, the variable named x is a parameter because it is given a value when the function is called.
Referencing is more common for variables whose values have large or unknown sizes when the code is compiled.
In a garbage-collected language (such as C#, Java, Python, Golang and Lisp), the runtime environment automatically reclaims objects when extant variables can no longer refer to them.
Unlike their mathematical counterparts, programming variables and constants commonly take multiple-character names, e.g.
In almost all languages, variable names cannot start with a digit (0–9) and cannot contain whitespace characters.
However, beyond the basic restrictions imposed by a language, the naming of variables is largely a matter of style.
Thus names of variables identify them, for the rest they are just a tool for programmers to make programs easier to write and understand.
Implicit Heap-Dynamic variables are bound to heap storage only when they are assigned values.