How do I call a variable that has the same name as a variable instantiated inside of an if-statement? Here's some code for reference:
int main() {
int x = 5;
if (x) {
int x = 2;
cout << x << endl; // should print out 2.
cout << ::x << endl; // should print out 5.
}
return 0;
}
I know that the second cout
line is incorrect, so what would the correct way of writing it be?