MCQ Hive stays free thanks to ads. Please disable your ad blocker for this site so content and features keep working.
Fundamental Programming
Variables & Scope
Beginner
Q
What are the scope and lifetime of a static local variable declared inside a C++ function?
ABlock scope and a lifetime of one function call
BBlock scope, but a lifetime equal to the whole program run
CGlobal scope and program lifetime
DFile scope and a lifetime of one function call
Correct Answer:
B. Block scope, but a lifetime equal to the whole program run
Explanation:
Scope (where the name is visible) and lifetime (how long the object exists) are separate properties. A static local is visible only in its block but lives until the program ends.