How to Run C and C++ Program in CMD

By | September 8, 2015

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.

How to Run C and C++ Program in CMD

2. Click on Advance system settings and then Environment Variables.

How to Run C and C++ Program in CMD

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.

How to Run C and C++ Program in CMD

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.

How to Run C and C++ Program in CMD
Comment below if you have any doubts regarding above how to run C and C++ program in CMD article.

Happy Coding!! 🙂 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *