Q:

In C++, what happens if two different functions declare the same static variable?

void foo() {
    static int x;
}

void bar() {
    static int x;
}

int main() {
    foo();
    bar();
}

A:

They each see only their own one.  A variable cannot be "seen" from outside the scope that it's declared in.
If, on the other hand, you did this:
static int x;

void foo() {
    static int x;
}

int main() {
    foo();
}

then foo() only sees its local x; the global x has been "hidden" by it.  But changes to one don't affect the value of the other.

A:

The variables are distinct, each function has it's own scope.  So although both variables last for the lifetime of the process, they do not interfere with each other.

A:

This is perfectly fine. In practice the actual name of the variable in the output of the compiler can be thought of as something like function_bar_x, i.e. it is the responsibility of your compiler to ensure that these do not clash.

