encyclopegia.org

Temporary variable

In computer programming, a temporary variable is a variable with short lifetime, usually to hold 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 as a local variable, i.e., a variable with local scope. 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 the contents of two variables. Temporary variables, along with XOR swaps and arithmetic operators, are one of three main ways to exchange 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 := b b := temp Temporary variables are usually named with identifiers that abbreviate the word temporary, such as temp, tmp or simply t, or with common metasyntactic variable names, the most common of which are foo, bar, baz (see also foobar). Computer hardware is designed to exploit the behaviour of temporary data: a cache or register file may contain temporaries internally to a microprocessor, such that they never need to be committed to main memory (hence consuming no external memory bandwidth).

In computer programming, a temporary variable is a variable with short lifetime, usually to hold 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 as a local variable, i.e., a variable with local scope. 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 the contents of two variables. Temporary variables, along with XOR swaps and arithmetic operators, are one of three main ways to exchange 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 := b b := temp Temporary variables are usually named with identifiers that abbreviate the word temporary, such as temp, tmp or simply t, or with common metasyntactic variable names, the most common of which are foo, bar, baz (see also foobar). Computer hardware is designed to exploit the behaviour of temporary data: a cache or register file may contain temporaries internally to a microprocessor, such that they never need to be committed to main memory (hence consuming no external memory bandwidth). ==See also== Temporary folder Temporary file Temporary filesystem ==References==

References

No reference rows published for this article.

Cite this article

MLA

"Temporary variable." encyclopegia.org, 2026, https://encyclopegia.org/wiki/temporary-variable. Accessed 24 November 2026.

Chicago

"Temporary variable." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/temporary-variable.

APA

encyclopegia.org. (2026). Temporary variable. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/temporary-variable

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Microsoft Assistance Markup Language

enwiki · references available

César De Paepe

enwiki · references available

Trademark (band)

enwiki · references available

Ilocano people

enwiki · references available

Purple fringing

enwiki · references available

Officer Qualification Record

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1345463805 · 0.5 · snapshot enwiki-001345463805

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.