It will run until something stops it. If you don't stop it, it will stop when there's a power outage, or when a truck crashes into your building and breaks the computer, or when your dog trips over the power cable and pulls it out of the wall.
Note: You can create loops that will eventually stop, e.g.:
while (1)
{
char *p = malloc(128); // allocate some memory
*p = 1;
}
will eventually run out of memory and crash (malloc
will return NULL, and *NULL will generally crash [though there are some kinds of computers where it won't]). You could also write:
int counter = 0;
while (1)
{
counter++;
if (counter == 10000)
break;
}
which isn't really infinite because it will only loop 10000 times, even though it has while(1)
.
Your program is neither of these, though. It's a real infinite loop which won't crash. (Note that printing to the screen will not run out of memory, because old text gets discarded)
Your program could stop if the user sets it up that way. If they're on Linux, they could run ./your_program | head -n10
, which will print the first 10 lines, then kill the program when it tries to print more lines. Or they could run timeout 10 ./your_program
which will kill the program after 10 seconds.
But if there's nothing that makes your program stop (not in the program, and not done by the user), it won't stop.