Temporary variable
Encyclopedia
In computer programming
Computer programming
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...

, a temporary variable is a variable
Variable (programming)
In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...

 whose purpose is short-lived, usually to hold temporary data that will soon be discarded, or before it can be placed at a more permanent memory location. Because it is short-lived, it is usually declared with local scope
Scope (programming)
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...

. There is no formal definition of what makes a variable temporary, but it is an often-used term in programming.

A typical example would be that of swapping
Swap (computer science)
In computer programming, the act of swapping two variables refers to mutually exchanging the values of the variables. Usually, this is done with the data in memory...

 the contents of two variables. To swap the contents of variables a and b one would typically use a temporary variable temp as follows, so as to preserve the data from a as it is being overwritten by b:

temp := a
a := b
b := temp

Temporary variables are usually named
Naming conventions (programming)
In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables, types and functions etc...

 with identifier
Identifier
An identifier is a name that identifies either a unique object or a unique class of objects, where the "object" or class may be an idea, physical [countable] object , or physical [noncountable] substance...

s that abbreviate
Abbreviation
An abbreviation is a shortened form of a word or phrase. Usually, but not always, it consists of a letter or group of letters taken from the word or phrase...

 the word temporary, such as temp, tmp or simply t, or
with common metasyntactic variable
Metasyntactic variable
In computer science, programmers use metasyntactic variables to describe a placeholder name or an alias term commonly used to denote the subject matter under discussion or an arbitrary member of a class of things under discussion...

 names, the most common of which are foo, bar, baz (see also foobar
Foobar
The terms foobar /ˈfʊːbɑː/, fubar, or foo, bar, baz and qux are sometimes used as placeholder names in computer programming or computer-related documentation...

). The letters i, j, k and so on are also frequently used for indices, a tradition stemming from early Fortran
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...

 and mathematics.

See also

  • Temporary folder
    Temporary folder
    In computing, a temporary folder or temporary directory is a directory used to hold temporary files. Many operating systems and some software automatically delete the contents of this directory at bootup or at regular intervals....

  • Temporary file
    Temporary file
    Temporary files may be created by computer programs for a variety of purposes; principally when a program cannot allocate enough memory for its tasks, when the program is working on data bigger than the architecture's address space, or as a primitive form of inter-process communication.- Auxiliary...

  • Temporary filesystem
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK