B.cpp
#include <iostream>
static int x=4;
void print_x() { std::cout<< x; }
A.cpp
#include <iostream>
void print_x(); //forward declaration
int x=3;
int main ()
{
std::cout<< x << " ";
print_x();
}
// output 3 4
i run this code in visual studio 2019 and i got this output but i expected found link error because when function get_x() excuted the linker will see two definitions first one is static x in B.cpp and second one is x in A.cpp because it's have externel linkage
so why this code is run correctly?