I was recently asked to consider the output of the following code:
#include <iostream>
int gvar;
int main (void)
{
cout << &gvar << endl;
while (true);
return 0;
}
This code is compiled and an executable is generated. If this executable in run 2 terminals in parallel. what would it print.
My reply was that it would print 2 different addresses. But on running, I found out in both the terminals same address was printed.
Can somebody explain why this is happening. I know that might be due to virtual memory but I am not able to put the pieces together.