Global variables
Variables declared outside all functions with scope extending throughout the entire program. Global variables exist for the program's entire execution. They enable data sharing between functions but reduce code modularity and testability. Overuse of globals complicates program understanding and debugging.
Real World
In an online multiplayer game like Fortnite, a global variable tracking the shrinking storm circle is accessible by every function — player damage, map rendering, and AI behaviour all read it.
Exam Focus
State both advantages (data sharing between functions) AND disadvantages (hard to debug, unintended side effects) for full marks.
How well did you know this?