Difference between revisions of "Variable"
m |
|||
Line 25: | Line 25: | ||
An identifier is the name used to reference either the the stored value or the variable itself; the variable's name can be used separately from the data it represents. | An identifier is the name used to reference either the the stored value or the variable itself; the variable's name can be used separately from the data it represents. | ||
− | |||
==Typing== | ==Typing== | ||
Line 53: | Line 52: | ||
− | + | =External Links= | |
− | |||
* [https://en.wikibooks.org/wiki/Computer_Programming/Variables Computer Programming/Variables] | * [https://en.wikibooks.org/wiki/Computer_Programming/Variables Computer Programming/Variables] | ||
* [http://openbookproject.net/thinkcs/python/english3e/variables_expressions_statements.html Variables, Expressions and Statements (Python)] | * [http://openbookproject.net/thinkcs/python/english3e/variables_expressions_statements.html Variables, Expressions and Statements (Python)] |
Revision as of 23:16, 9 July 2019
Definition
In programming, a variable is comprised of:
- a storage location (identified by a memory address)
- an identifier
- value (a known or unknown quantity of information)
Relevance
Explanation
As the name variable implies, information may change as the program executes. However, its name, type, and location often remain fixed.
A Compiler will replace a variable's identifier with the data location.
Scalar: an alternative term for a variable.
Identifier
An identifier is the name used to reference either the the stored value or the variable itself; the variable's name can be used separately from the data it represents.
Typing
Changing the type of data stored in a variable may change the way the data can be used. For example, in most programming languages two integers added together will produce a sum that is also an integer.
class Math () {
a = 1;
b= 2;
c = a+b; // c will be 3
}
However, if a is a string (such as "hello"), adding it to an integer would not necessarily provide you with an integer as a result.
a = "hello";
b= 2;
c = a+b; // c will be hello2