0

I am not sure why my program is not showing "Hello World". I am trying by executing only printf(). Is there anything I am missing here?

Below is my complete program

#include <stdio.h>
int main()
{
    printf("Hello World");
    return 0;
}
10
  • online compiler? try adding a \n at the end of the printf statement. Commented Nov 18, 2015 at 15:03
  • or, fflush(stdout) after the current printf. Commented Nov 18, 2015 at 15:03
  • 1
    @SouravGhosh, i think before the program exits, the buffer will flush. Commented Nov 18, 2015 at 15:04
  • @Haris please note the first two words in my very first comment. :) Commented Nov 18, 2015 at 15:05
  • How do you run your program? What compiler are you using`Which version of the compiler? On which operating system? Commented Nov 18, 2015 at 15:05

1 Answer 1

3

My guess is that the console window which contains the output flashes by so quickly that you don't have time to see it. You need to put in something to halt the program so you can see the output. One way of doing it is to ask the user to press the Enter key.

Something like

#include <stdio.h>

int main(void)
{
    printf("Hello World\n");
    printf("Press the Enter key to continue\n");
    (void) getc(stdin);
    return 0;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.