Q:

Code before while(1) does not run

I have code like this below:
#include <stdio.h>

int main(int argc, char *argv[]) {
    printf("hello");

    while(1){
        // whatever here
    }
}

and the question is: why the first instruction is skipped? It runs only the loop, hello is never printed. I compiled it with gcc and g++ with the same result.

A:

It does run, it's just that the output buffer is not flushed before your while.
Use printf("hello\n"); instead. The newline character will flush the buffer so writing the output immediately to your console.

A:

Your assumption is wrong, your code does run, only stdout is not flushed, but buffered.
Use fflush(stdout) after printf("hello"), this forces stdout to be printed.
And, as @Bathsheba pointed out, also a newline character ("\n") within the printf forces it to flush, which is explained in this SO question.

