Recall & Review
beginner
What is scope in C programming?
Scope is the part of the program where a variable or function is accessible or visible.
Click to reveal answer
beginner
What does lifetime of a variable mean in C?
Lifetime is the period during program execution when the variable exists in memory and holds a value.
Click to reveal answer
intermediate
Compare local and global variable scope.
Local variables are accessible only inside the block or function they are declared in. Global variables are accessible throughout the entire program after their declaration.
Click to reveal answer
intermediate
How does the lifetime of a local variable differ from a global variable?
Local variables exist only while the function or block runs. Global variables exist for the entire program run.
Click to reveal answer
advanced
What is the lifetime and scope of a
static variable inside a function?A static variable inside a function has a lifetime for the entire program run but its scope is limited to that function only.
Click to reveal answer
Where is a local variable accessible in C?
✗ Incorrect
Local variables are only accessible inside the block or function where they are declared.
What happens to a local variable's value after the function ends?
✗ Incorrect
Local variables exist only while the function runs; after it ends, their values are lost.
What is true about a global variable's lifetime?
✗ Incorrect
Global variables exist for the whole time the program runs.
What does the
static keyword do to a variable inside a function?✗ Incorrect
Static variables inside functions keep their value between calls but are only accessible inside that function.
Which variable has the widest scope in C?
✗ Incorrect
Global variables can be accessed anywhere after their declaration.
Explain the difference between scope and lifetime of a variable in C.
Think about where a variable can be used versus how long it exists.
You got /3 concepts.
Describe how a static variable inside a function behaves in terms of scope and lifetime.
Consider how static changes the usual local variable behavior.
You got /3 concepts.