#2. Compiling the First C Program
Now that you’ve read/seen what C code/program looks like(If you’ve not read the #C_Basics series, I’ll leave a link below for it), before proceeding to write the first program, the user needs to set up a C program compiler, which would compile and execute the “Hello World” program. Here we have used a Windows-based GCC compiler to compile and run the program. To know more on how to set up the local GCC compiler or run using online ide refer to Setting C Development Environment.
Step 1: This requires writing the “Hello World” program, in a text editor and saving the file with the extension .c, for example, we have stored the program in a C-type file HelloWorld.c.
Step 2: This includes opening CMD or command prompt line and navigating to the directory where the file HelloWorld.c is present.
Step 3: To compile the code execute the following command:
gcc HelloWorld.c
This would create a C-executable file with a random name given by the compiler itself. We got the executable filename as a.
To give a user-oriented name, run the following command:
gcc -o helloworld HelloWorld.c/pre>
This would create a C-executable file by the name helloworld.
Step 4: To run the executable file to get the result, just run the file.
helloworld
Understanding C program Compilation Process
If you haven’t yet, check out C Basics: C Comments using this link:
And feel free to read C Introductions: “Hello, World!”