InterviewSolution
| 1. |
Can You Please Explain The Scope Of Static Variables? |
|
Answer» Static variables in C have the scopes;
The static variables are available to the program, not only for the function / block. It has the scope within the current compile. When static variable is declared in a function, the value of the variable is preserved , so that successive calls to that function can use the latest updated value. The static variables are INITIALIZED at compile time and kept in the executable file itself. The life time extends across the complete run of the program. Static local variables have local scope. The difference is, storage duration. The values put into the local static variables, will still be present, when the function is invoked next time. Static variables in C have the scopes; The static variables are available to the program, not only for the function / block. It has the scope within the current compile. When static variable is declared in a function, the value of the variable is preserved , so that successive calls to that function can use the latest updated value. The static variables are initialized at compile time and kept in the executable file itself. The life time extends across the complete run of the program. Static local variables have local scope. The difference is, storage duration. The values put into the local static variables, will still be present, when the function is invoked next time. |
|