0
0
Cprogramming~5 mins

Lifetime and scope comparison - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThroughout the entire program
BOnly inside the block or function it is declared in
COnly inside the header files
DNowhere, it is not accessible
What happens to a local variable's value after the function ends?
AIt is copied to all other functions
BIt remains stored in memory
CIt becomes a global variable
DIt is lost because the variable's lifetime ends
What is true about a global variable's lifetime?
AIt lasts only inside one function
BIt lasts only during compilation
CIt lasts for the entire program execution
DIt lasts only inside a block
What does the static keyword do to a variable inside a function?
AKeeps the variable alive for the whole program but limits its scope to the function
BMakes the variable global
CDeletes the variable after the function ends
DMakes the variable accessible everywhere
Which variable has the widest scope in C?
AGlobal variable
BLocal variable
CStatic variable inside a function
DFunction parameter
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.