In this article I want to show you all how to run a C-Program in command prompt/ line on a Windows operating system! Be sure to install C-Programming compiler first (gcc). If this article is helpful to ya please leave some claps ! I would really appreciate it!
Step0: Install C-Program Compiler (gcc)
You will need a C compiler to do this already installed, I use GCC. https://gcc.gnu.org/. If you are on a Windows computer, you can run the command gcc -v to check if it’s already installed. If gcc is installed then it should display a host of information starting with the sentence “Using built-in specs”.
Create your C-Program, I have created a simple program that prints “Hello World!” to the screen, and saved it as helloWorld.c . See the code below:
# include <stdio.h>
Open the command prompt by clicking start button → All Apps → Windows System folder → Click Command Prompt. You can see the exact steps here.
Change our directory to where you have your C program (helloWorld.c). You can do that by using the command ‘cd’, I saved my helloWorld.c program on my desktop. See below example:
Run the command “gcc”(the C-compiler ) followed by the full name of your program (helloWorld.c) in the command prompt. This will compile your source code and create an executable file on your desktop. See below example: gcc <name_of_file>
NOTE: The executable file named itself probably something like ‘a.exe’. Which is fine because we never told the compiler what to name the executable file.
Let’s name our executable file instead of letting the compiler do it for us. We can name the executable file by running this command in command prompt
gcc -o <name_of_executable> <name_of_source_code>
For example, I will name the executable file “hello” and the source code is “helloWorld.c”:
gcc -o hello helloWorld.c
In this step we will run our program (the executable file) in command prompt, this can be achieved by going to the directory of the executable file in command prompt (my executable is in the same directory as my source file), then type the name of the executable file without the extension (my executable file name was hello.exe) so I typed the following:
Notice: Your program should now have been executed, my program printed “Hello World!” to the command prompt !
If you want to learn more about the C Programming Language, you have to read the book “C Programming Language”. This book goes into topics like data structures, arrays, statement blocks, recursion, loops, arithmetic operations, type conversions, bitwise operators, and pointers. The list goes on.
Thanks for reading this article I hope its helpful to you all ! Keep up the learning, and if you would like more computer science, programming and algorithm analysis videos please visit and subscribe to my YouTube channels (randerson112358 & compsci112358 )
Check Out the following for content / videos on Computer Science, Algorithm Analysis, Programming and Logic:
Video Tutorials on Recurrence Relation:
Video Tutorial on Algorithm Analysis: