To be pedantic: there are no global variables in C. Variables have scope, storage duration and linkage. For none of these there exists a 'global' qualification.
So what is going on, then? Your
int my_private_value;
is a variable with with file scope and external linkage (and static storage duration). This type of linkage means it can be referenced from any other file that has an extern int my_private_value
declaration in scope. To avoid this, the variable must have internal linkage. To declare a variable with internal linkage, use the static
keyword:
static int my_private_value;
So, if you wanna sound like a professional, whenever you are tempted to utter 'global variable', take a deep breath and speak the words object with file scope and external linkage. That'll make you shine in all C interviews :-)
Should somebody question your wisdom about the lack of "global" variables, you can even prove it to them. Global variables are in scope everywhere, right? But in C, the scope of an object starts not until its declaration. The lack of a truly global variable makes it impossible to forward reference a variable like in
int *foo = &bar; /* Doesn't work in C: bar is not (yet) in scope. */
int bar = 42;
It does work when you swap the two lines.