The problem is that Windows has poor support for running non-GUI programs.
A common way to run a program under Windows is to double-click the executable from an explorer window. For a program like yours that just prints to standard output, this will open a new window for the program's output, the program will run and quickly finish, and Windows will immediately close the window, perhaps before you have a chance to see it.
A common workaround is to add something to the end of your program, such as a call to getchar()
, to cause the program to wait for input.
Another solution is to run the program from a command prompt. Its output will then appear in the current window rather than in a temporary one, and you'll see the program's output followed by a new prompt. If you run it that way, and added getchar()
is unnecessary, and will make the program wait for input before terminating.
The Windows OS emphasizes GUI programs rather than programs that use plain text input and output. C was developed in a different kind of environment (though of course implementations of C for Windows support graphical operations).