Is there any difference between a variable declared as static outside any function between C and C++. I read that static means file scope and the variables will not be accessible outside the file. I also read that in C, global variables are static . So does that mean that global variables in C can not be accessed in another file?
Is there any difference between a variable declared as static outside any function between
Share
No, there’s no difference between C and C++ in this respect.
Read this SO answer about what
staticmeans in a C program. In C++ there are a couple of other meanings related to the use ofstaticfor class variables (instead of instance variables).Regarding global vars being
static– only from the point of view of memory allocation (they are allocated on the data segment, as all globals are). From the point of view of visibility: