tavianator
Programmer
could someone please explain to me why this code produces
1: 3
2: 2
3: 1
as-is, and
1: 1
2: 2
3: 3
when uncommented?
1: 3
2: 2
3: 1
as-is, and
1: 1
2: 2
3: 3
when uncommented?
Code:
int foo()
{
static int i = 0;
return ++i;
}
int main(int argc, char* argv[])
{
std::cout << "1: " << foo() << std::endl//;
/*std::cout*/ << "2: " << foo() << std::endl//;
/*std::cout*/ << "3: " << foo() << std::endl;
return 0;
}