Why does this hang without first printing?
#include <stdio.h>
void main() {
printf("hello world");
while (1) {}
}
Why does this hang without first printing?
#include <stdio.h>
void main() {
printf("hello world");
while (1) {}
}
Because you haven't flushed the standard output. Try fflush
. Even better, for C++ use...
std::cout << "hello world" << std::endl;
Separately, you'd have a better chance of it flushing itself if you added a \n
, but not all implementations follow the Standard when it comes to such things.
Call fflush(stdout);
after printf
.
This will force the stdout buffer to be flushed and printed.