[Solved] Why don’t people initialize i globally?


Excellent idea!

Here’s a program that prints “hellohello” five times:

int i;

void print_twice(const std::string& s)
{
    for (i = 0; i < 2; i++)
    {
        std::cout << s;
    }
    std::cout << std::endl;
}

int main()
{
    for (i = 0; i < 5; i++)
    {
        print_twice("hello");
    }
}

Or… does it? (Ominous organ music plays. The crows caw. Sirens in the distance.)

0

solved Why don’t people initialize i globally?