0
0
Cprogramming~5 mins

Static storage class - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AIt keeps its value and exists until the program ends.
BIt is destroyed and loses its value.
CIt becomes a global variable.
DIt resets to zero automatically.
Declaring a global variable as static means:
AIt becomes a local variable.
BIt can be accessed from any file.
CIt is only accessible within the file it is declared.
DIt is deleted after main() ends.
Which keyword in C makes a variable keep its value between function calls?
Astatic
Bregister
Cextern
Dauto
If you want a variable to be visible only inside one source file, which keyword should you use?
Aextern
Bstatic
Cauto
Dregister
What is the initial value of a static variable if not explicitly initialized?
ARandom garbage value
BOne
CDepends on compiler
DZero or NULL
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.