clinuxfunctionpauseunistd.h

Why pause() function prevents seeing console output in C?


I'm a little bit confused how does the function pause() works in the sense of calling order. For example:

int main(){
     printf("Start\n");
     pause();
     printf("Finish\n");
}

I was expecting to get output "Start" before pause, but program just immediately pauses instead. Please, explain why. Thanks in advance.


Solution

  • Your terminal emulator doesn't apparently flush standard output on every newline. You can manually flush it with fflush(stdout) if you want to see the output immediately:

    int main(){
         printf("Start\n");
         fflush(stdout);
         pause();
         printf("Finish\n");
    }