Global variable

Missing image
Merge_articles.png


It has been proposed that this article or section be merged with scope (computer science).

This request may be discussed on the article's talk page.

In computer programming, a global variable is a variable that does not belong to any subroutine in particular and can therefore can be accessed from any context in a program. They are contrasted with local variables. See also, scope.

They are usually considered bad practice precisely because of their nonlocality: a global variable can potentially be modified from anywhere, and any part of the program may depend on it. A global variable therefore has an unlimited potential for creating mutual dependencies, and adding mutual dependencies increases complexity. See Action at a distance. However, in a few cases, global variables can be suitable for use. They can be used to avoid having to pass frequently-used variables continuously throughout several functions, for example.

Compare this with a constant, which can be seen as a read-only global variable (even though this use of variable is an oxymoron). Because a constant, by virtue of its constancy, can only be "modified" (defined) at one point in the program, all dependencies on a constant are one-way.

See Also

Template:Compu-sci-stub

pl:Zmienna globalna

Navigation
  • Home Page (https://academickids.com/)
  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (https://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (https://academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (https://academickids.com/encyclopedia/index.php/Clipart)
  • Geography (https://academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (https:/academickids.com/encyclopedia/index.php/Countries)
    • Maps (https://academickids.com/encyclopedia/index.php/Maps)
    • Flags (https://academickids.com/encyclopedia/index.php/Flags)
    • Continents (https://academickids.com/encyclopedia/index.php/Continents)
  • History (https://academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (https://academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (https://academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (https://academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (https://academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (https://academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (https://academickids.com/encyclopedia/index.php/Timelines)
    • United States (https://academickids.com/encyclopedia/index.php/United_States)
    • Wars (https://academickids.com/encyclopedia/index.php/Wars)
    • World History (https://academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (https://academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (https://academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (https://academickids.com/encyclopedia/index.php/Reference)
  • Science (https://academickids.com/encyclopedia/index.php/Science)
    • Animals (https://academickids.com/encyclopedia/index.php/Animals)
    • Aviation (https://academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (https://academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (https://academickids.com/encyclopedia/index.php/Earth)
    • Inventions (https://academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (https://academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (https://academickids.com/encyclopedia/index.php/Plants)
    • Scientists (https://academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (https://academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (https://academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (https://academickids.com/encyclopedia/index.php/Economics)
    • Government (https://academickids.com/encyclopedia/index.php/Government)
    • Religion (https://academickids.com/encyclopedia/index.php/Religion)
    • Holidays (https://academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (https://academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (https://academickids.com/encyclopedia/index.php/Planets)
  • Sports (https://academickids.com/encyclopedia/index.php/Sports)
  • Timelines (https://academickids.com/encyclopedia/index.php/Timelines)
  • Weather (https://academickids.com/encyclopedia/index.php/Weather)
  • US States (https://academickids.com/encyclopedia/index.php/US_States)

Information

  • Contact Us (https://academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (https://classroomclipart.com)
Toolbox
Personal tools