Variable scope
The region of code where a variable is accessible and can be referenced. Scope rules determine variable visibility and lifetime. Common scope levels include global (program-wide), local (function-level), and block (if/loop statements). Proper scoping prevents naming conflicts and improves code clarity.
Real World
In Tesla's self-driving software, sensor readings are local to each processing function so a camera module cannot accidentally overwrite lidar data — scope rules enforce this isolation automatically.
Exam Focus
Use a code trace showing the same variable name in two scopes with different values — examiners reward clear scope-resolution understanding.
How well did you know this?