Question:

What is static variable ?

Show Hint

A static variable inside a function acts like a variable with memory. It remembers its value from the last time the function was called.
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

A static variable is a variable that is allocated for the entire lifetime of the program. Its value is preserved between function calls or, if it's a class member, it is shared among all instances (objects) of that class. Key properties:

Lifetime: It exists from the start of the program to its end.
Initialization: It is initialized only once, usually to zero by default if not explicitly initialized.
Scope: If defined inside a function, its scope is local, but its value persists. If defined as a class member, it belongs to the class itself, not to individual objects.
Was this answer helpful?
0
0