What is the difference between declaring static variable inside a block and outside a block in a file? Eg, here, what is difference between static variables a,b,c,d? Can we
static int a;//file scope variable
void getVol()
{
static int b;//fixed duration
}
File scoped variables act exactly like global variables, except their use is restricted to the file in which they are declared (which means you can not extern them to other files). A fixed duration variable is one that retains it’s value even after the scope in which it has been created has been exited! Fixed duration variables are only created (and initialized) once, and then they are persisted throughout the life of the program. Check this link:http://www.learncpp.com/cpp-tutorial/43-file-scope-and-the-static-keyword/