Before a program can run, the source code has to be translated into an executable format by a compiler. This step transforms the human-readable source code into binary machine code, which is a sequence of instructions that can be executed by a computer.
Visual Studio Compilation
Continuing from the last chapter, the Hello World program is now complete and ready to be compiled and run. You can do this by going to the Build menu and choosing Debug ➤ Start Without Debugging (Ctrl+F5). Visual Studio then compiles and runs the application that displays the text in a console window.
Depending on your version of Visual Studio, the console window displaying Hello World may close as soon as the main function has finished executing. To prevent this, you need to explicitly specify that this is a console application. First right-click the Project node in the Solution Explorer and then click on Properties to bring up the project’s properties window. From there, navigate to Configuration Properties ➤ Linker ➤ System and set the SubSystem option to Console using the dropdown list. Click OK and the console window will now no longer close automatically.
Console Compilation
As an alternative to using an IDE, you can also compile source files from a terminal window as long as you have a C compiler. For example, on a Linux machine you can use the GNU C compiler, which is available on virtually all UNIX systems—including Linux and the BSD family—as part of the GNU Compiler Collection (GCC). This compiler can also be installed on Windows by downloading MinGW1 or on Mac as part of the Xcode development environment.2
Comments
Keep in mind that whitespace characters—such as comments, spaces, and tabs—are generally ignored by the compiler. This gives you a lot of freedom in how you format your code.