Interactive Computer Science Tutoring

Learn programming concepts interactively

AHA Schools Logo

C Variable Scope

Understanding variable visibility and lifetime in C

Scope Examples
Explore different types of variable scope in C
Code Execution
Step through code to see scope changes
Variable Visibility
See which variables are currently in scope
Currently Visible Variables:
No variables in current scope
Scope Tree Visualization
Toggle the hierarchical scope display
Scope Challenge
Test your understanding of C scope rules
What happens when an inner block declares a variable with the same name as an outer variable?
Scope Example Code
Interactive C code with memory visualization
Scope Hierarchy
Active Scopes:
Global ScopeActive
main() Function
int a = 12
if Block
int b = 99
Scope Exploration Log0/5
Recent operations with timestamps

No operations yet

Start by adding or modifying elements

Scope Rules Summary
📦 Block Scope
Variables declared in blocks are only visible within that block
🌍 File Scope
Variables declared outside functions are visible to all subsequent functions
🔄 Variable Hiding
Inner variables with same name hide outer variables in scope chain
Common Scope Mistakes
Using Variables Out of Scope
Trying to access variables after their scope has ended
Unintentional Variable Hiding
Declaring variables with same name in nested scopes
Scope Confusion in Loops
Forgetting that loop variables have loop scope