Recall & Review
beginner
What does the
static keyword do when used with a variable inside a function in C?It makes the variable keep its value between function calls instead of being reinitialized each time the function runs.
Click to reveal answer
beginner
How does a
static variable inside a function differ from a normal local variable?A normal local variable is created and destroyed each time the function runs, but a static variable is created once and keeps its value between calls.
Click to reveal answer
intermediate
What is the effect of declaring a global variable as
static in C?It limits the variable's scope to the file where it is declared, so it cannot be accessed from other files.
Click to reveal answer
beginner
Why would you use a
static variable inside a function?To remember information between function calls without using global variables, like counting how many times the function was called.
Click to reveal answer
beginner
Can a
static variable inside a function be accessed outside that function?No, it has local scope limited to the function, but its value persists between calls.
Click to reveal answer
What happens to a
static variable inside a function after the function finishes?✗ Incorrect
A static variable inside a function keeps its value and exists for the entire program run.
Declaring a global variable as
static means:✗ Incorrect
Static global variables have file scope, so they cannot be accessed from other files.
Which keyword in C makes a variable keep its value between function calls?
✗ Incorrect
The static keyword makes a variable retain its value between calls.
If you want a variable to be visible only inside one source file, which keyword should you use?
✗ Incorrect
Static limits the scope of global variables to the file they are declared in.
What is the initial value of a static variable if not explicitly initialized?
✗ Incorrect
Static variables are automatically initialized to zero if not set by the programmer.
Explain how the
static storage class affects the lifetime and scope of variables in C.Think about how long the variable exists and where it can be accessed.
You got /3 concepts.
Describe a practical example where using a
static variable inside a function is helpful.Imagine a function that needs to remember something each time it runs.
You got /3 concepts.