In this article I will tell you how to run C and C++ program in CMD.
CMD or Command Prompt is a command line interpreter in Windows operating system. Running C and C++ programs using command prompt is useful in case you don’t have an IDE installed in your system.
Also Read: Configure Notepad++ to Run C, C++ and Java Programs
Things you will need
You must have a C or C++ compiler like GCC, Visual C++, etc. already installed in your system. If you don’t have any, you can easily get them by searching on Google.
How to Run C and C++ Program in CMD
1.Before running programs we must set the path of compiler. So, first right click on Computer icon and go to Properties option.
2. Click on Advance system settings and then Environment Variables.
3. A new window will open, there click on New button. In Variable name filed enter path and in Variable value filed enter the path of the bin folder of compiler.
4. You can find the path of bin folder by going to the directory where you have installed the compiler.
5. After that click all OK buttons to save the information.
6. Press Win+R keys to open Run. Type cmd and press enter to open command prompt.
7. Now change the directory to where you have saved your C or C++ program file. Lets say you have saved the program on Desktop then type cd desktop and press enter.
8. Now for compiling the program type gcc filename. Here filename is the name of the program file. I have used gcc command because I have installed GCC compiler in my system. The command will change if you are using any other compiler, like for Turbo C++ it will be tcc, for Borland C++ it will be bcc and so on.
9. For running the program just type the name of the source file without .c or .cpp extension and press enter.
10. If you have followed steps properly then you can see the output.
Comment below if you have any doubts regarding above how to run C and C++ program in CMD article.
Happy Coding!! 🙂 🙂
13 thoughts on “How to Run C and C++ Program in CMD”
we are unable to run the program in windows 7
i need a video of how to run a c++ program
g++ first.cpp -o first.exe
compiler code :
g++ first.cpp -o first.exe
change the system variable path not the user variable.
where u got the jdk for c and c++ cmd
Love that this actually works, using exactly what I am doing in Dev-Cpp
thanks a lot ! it works!
Follow the same steps till Environment variables. After you reach environment variables, click on Path in System variables instead of Admin and edit the path and follow the rest specified step simultaneously. Happy Coding!
Thanks buddy it worked like a charm!!!
Great piece of advice! Thank you guys!