Difference between revisions of "Variable"

esse quam videri
Jump to: navigation, search
(Naming Conventions)
(Definition)
 
(17 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
# an ''[[Identifier|identifier]]''
 
# an ''[[Identifier|identifier]]''
 
# ''[[Value|value]]'' (a known or unknown quantity of information)
 
# ''[[Value|value]]'' (a known or unknown quantity of information)
 +
 +
[[File:VariableVisual.jpg|400px]]
  
 
=Relevance=
 
=Relevance=
 +
* [[Field]]
 +
* [[Property]]
 +
* [[Constant]]
 +
* [[Data Type]]
 +
* [[Identifier]]
 +
* [[Keyword]]
  
 
=Explanation=
 
=Explanation=
Line 14: Line 22:
 
A [[compiler|Compiler]] will replace a variable's identifier with the data location.  
 
A [[compiler|Compiler]] will replace a variable's identifier with the data location.  
  
'''scalar''': an alternative term for a variable.
+
'''Scalar''': an alternative term for a variable.
 
 
  
 
==Identifier==
 
==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.  
 
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.  
 
== Scope ==
 
 
Local
 
 
Global
 
 
Block
 
  
 
==Typing==
 
==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.  
 
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.  
  
<code>
+
<syntaxhighlight lang="csharp">
 +
class Math () {
 
a = 1;
 
a = 1;
  
Line 38: Line 38:
  
 
c = a+b; // c will be 3
 
c = a+b; // c will be 3
 +
}
  
</code>
+
</syntaxhighlight>
  
 
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.
 
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.
Line 52: Line 53:
 
</code>
 
</code>
  
===Strong Typing===
+
=External Links=
 
+
* [https://en.wikibooks.org/wiki/Computer_Programming/Variables Computer Programming/Variables]
==Memory Allocation==
+
* [http://openbookproject.net/thinkcs/python/english3e/variables_expressions_statements.html Variables, Expressions and Statements (Python)]
 
+
* [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/var C# Var]
===Garbage Collection===
 
 
 
==Naming Conventions==
 
 
 
==Variable Types==
 
There are many types of variables, such as: static, stack-dynamic, explicit heap-dynamic, and implicit heap-dynamic.
 
===Static===
 
A static variable is also known as global variable, it is bound to a memory cell before execution begins and remains to the same memory cell until termination. A typical example is the static variables in C and C++.
 
 
 
===Static-Dynamic===
 
A Stack-dynamic variable is known as local variable, which is bound when the declaration statement is executed, and it is deallocated when the procedure returns. The main examples are local variables in C subprograms and Java methods.
 
===Explicit Heap Dynamic===
 
Explicit Heap-Dynamic variables are nameless (abstract) memory cells that are allocated and deallocated by explicit run-time instructions specified by the programmer. The main examples are dynamic objects in C++ (via new and delete) and all objects in Java.
 
===Implicit Heap-Dynamic===
 
Implicit Heap-Dynamic variables are bound to heap storage only when they are assigned values. Allocation and release occur when values are reassigned to variables. As a result, Implicit heap-dynamic variables have the highest degree of flexibility. The main examples are some variables in JavaScript, PHP and all variables in APL.
 
=Resources=
 
== See also ==
 
 
 
* [[Constant]]
 
* [[Data Type]]
 
* [[Identifier]]
 
* [[Keyword]]
 
 
 
==Notes==
 
 
 
 
 
==External Links==
 
* [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)]
 
  
  
{{DEFAULTSORT:Programming Language Concepts}}
 
 
[[Category:Programming Language Concepts]]
 
[[Category:Programming Language Concepts]]
 
[[Category:Data Type]]
 
[[Category:Data Type]]
 +
[[Category:Object Oriented Programming]]

Latest revision as of 15:21, 22 July 2019

Definition

In programming, a variable is comprised of:

  1. a storage location (identified by a memory address)
  2. an identifier
  3. value (a known or unknown quantity of information)

VariableVisual.jpg

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

External Links