Difference between File Scope and Global Scope

c, c++, global-scope, scope

Solution

A 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.

Problem

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.

Original source

Related problems