Why does the following code compiles, under g++, with out any warning or error? The problem I see is that the variable x defined in the first line is accessible inside the if scope but in spite that it's redefined again.
int main() {
int x = 5;
std::cout << x;
if (true) {
int x = 6;
std::cout << x;
}
}
See Question&Answers more detail:os