Unreferenced variable

An unreferenced variable in the source code of a computer program is a variable that is defined but which is never used. This may result in a harmless waste of memory. Many compilers detect such variables and do not allocate storage for them (i.e., "optimize away" their storage), generally also issuing a warning as they do.

Some coding guideline documents consider an unreferenced variable to be a symptom of a potential coding fault. On the other hand, unreferenced variables can be used as temporary placeholders to indicate further expected future developments in the code.

Examples

C:

 int main(void)
 {
   int i, j;
   for (i=0; i<10; i++)
      printf("%d", i);
   return 0;
 }

In this example, j is an unreferenced variable.


    gollark: It's a function, not some sort of syntactic construct, and also apiologically generalized, yes.
    gollark: I mean, it has constructs you can use as them, but not literal for loops.
    gollark: For example, Haskell. You may be aware of Haskell.
    gollark: > Every language has for loops, even Macron.This is objectively wrong.
    gollark: > If I have to add my numbers in Polish notation, I'm not really in control of my code.bees you.
    This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.