fbpx
Wikipedia

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 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 edit

temporary, variable, this, article, does, cite, sources, please, help, improve, this, article, adding, citations, reliable, sources, unsourced, material, challenged, removed, find, sources, news, newspapers, books, scholar, jstor, december, 2009, learn, when, . This article does not cite any sources Please help improve this article by adding citations to reliable sources Unsourced material may be challenged and removed Find sources Temporary variable news newspapers books scholar JSTOR December 2009 Learn how and when to remove this template message 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 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 editTemporary folder Temporary file Temporary filesystem Retrieved from https en wikipedia org w index php title Temporary variable amp oldid 1145791254, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.