I wonder why this C++ code is valid and doesn't cause any errors:
extern int B;
int A = B;
int B = A;
int main()
{
printf("%d\n", B);
system("pause");
return 0;
}
First, the variable A
will be created in some memory address, then its value will be initialized from variable B
, but then variable B
goes back to initialize its value from variable A
, and so on, ...
So, why is there no infinity loop or any error here?
The program still runs ok, and the value of B
is 0
This is valid for Java as well:
class A {
static final int AA = B.BB;
}
class B {
static final int BB = A.AA;
}
Any one can explain these questions for me, thanks!