I am a student and I am confused about global and file scope variables in C and C++. Is there any difference in both perspectives? If yes, please explain in detail.
See Question&Answers more detail:osI am a student and I am confused about global and file scope variables in C and C++. Is there any difference in both perspectives? If yes, please explain in detail.
See Question&Answers more detail:osA variable with file scope can be accessed by any function or block within a single file. To declare a file scoped variable, simply declare a variable outside of a block (same as a global variable) but use the static keyword.
static int nValue; // file scoped variable
float fValue; // global variable
int main()
{
double dValue; // local variable
}
File scoped variables act exactly like global variables, except their use is restricted to the file in which they are declared.