Well, I want to know why this code works, I just realized that I have two variables with the same name within the same scope.
It looks like you are confused by areas. They are not "located in the same area" ... the for k loop has its own nested / inner area. More importantly, to understand why language allows this, consider:
#define DO_SOMETHING \
do { for (int i = 1; i <= 2; ++i) std::cout << i << '\n'; } while (false)
void f()
{
for (int i = 1; i <= 10; ++i)
DO_SOMETHING();
}
, "DO_SOMETHING", , i. DO_SOMETHING, , - i - , , . - , , , , . , : , .
, , - . , , () ( , : ( , ( - , )).