Installing C/C++ In Windows With Visual Studio Code 2022

If you are struggling to correctly install C++ in Windows or C in Windows PC with Visual Studio Code and MinGW then your struggle ends here. In this article, I’ll guide you step by step on how to properly install and configure C/C++ in Windows with Visual Studio Code and MinGW.

c/c++ in windows

Follow the steps given below to install and configure C/C++ in Windows:

Step 1 : Installing VS Code

The very first step is to install Microsoft Virtual Studio Code in your Windows. Well, one can use other code editors too like Sublime Text Editor but, I would recommend you to install Microsoft’s Visual Studio Code. To install VS code follow the steps given below :

  • Click here to visit download page of Visual Studio Code.
  • After that click on Windows button to start downloading VS Code for Windows.

    Vs Code Download

  • You’ll see thank you message and your visual studio code will start downlaoding.

    Vs Code Downloading

  • After Visual Studio Code setup is downloaded run the setup and accept the agreement. After that click on next button.

    VS code setup

  • Select the destination where you want to install Visual Studio Code and then click on Next button.

    Vs code select destination

  • Select Start Menu folder and then click on Next button. I would recommend you to leave it as it is and then click on Next button.

    vs code select start menu

  • In Select addtional tasks section, make sure to check all the boxes and then click on Next button.

    VS code setup select additional tasks

  • Now Visual Studio Code is ready to get installed, so click on Install button to start installing Microsoft Visual Studio Code.

    VS Code ready to install

  • Installation will take some time, and after it is completed click on finish button to exit the VS code setup.

    VS code installation completed

Now that we’ve installed Microsoft Visual Studio code to write our C/C++ programs. Let’s install the MinGW compiler for our C/C++ Programs.

14 Amazing VS Code Tips To Increase Productivity And Speed

Step 2 : Downloading and setting up MinGW For C/C++ in Windows

In this step, we are going to download MinGW and set it up so that we can compile our C/C++ programs in windows without any errors.

  • Click here to visit the download page of MinGW.


  • Download the lastest version of MinGW from download section.
  • After the download is completed, run the MinGW setup and then extract it in Local Disk C. Anyway you can extract it anywhere but, I would recommend you to extract it in Local Disk C.


  • After the extraction is completed, you’ll see MinGW folder at thee place you extracted it. In my case it is in Local Disk C cause I extracted MinGW setup in Local Disk C.


Now that we’ve installed MinGW, let’s set up environment variable path for MinGW in windows so that we can compile and run C/C++ programs in Windows.

Setting Up Envoirnment Variable For C/C++ In Windows

  • To setup envoirnment variable path for MinGW, get inside of bin folder that is in MinGW folder.

    mingw/bin folder for c/c++ in windows

  • Copy the path of this folder from address bar of file explorer.

    mingw path for c in windows

  • Now right click on This PC and then click on Properties.

    mingw setup path for c in windows

  • Now from porperties click on Advanced system settings.

    setting up path for mingw for c++ in windows

  • From Advanced system settings click on Environment Variables.

    advanced system settings

  • Now in Environment Variables select Path and then click on Edit.

    environment variables for c++ in windows

  • Here click on New button to create a new path and then paste the path you’ve copied and then click on OK button to save it.

    mingw path for c++ in windows

We’ve successfully setup MinGW and it’s path for environment variable so that we can use gcc to compile and run C/C++ in Windows PC.

Checking MinGW Installation

To confirm if MinGW is installed or not properly in your windows PC. Type the gcc command in your windows terminal. If you see a fatal error message as shown in the image below, that means you’ve installed MinGW in your Windows properly.

gcc for c++ in windows
gcc installed successfully

You can also check your gcc version using the command gcc --version in your terminal.

gcc --version command
gcc –version

Installing C/C++ IntelliSense In VS Code

Now we are ready to write and run C/C++ in Windows PC but, before that, I would like to tell you about a VS code extension that will help you in writing C/C++ code.

C/C++ Intellisense is a VS Code extension that helps in writing C/C++ code faster. So to install it get in the VS code extensions section, search for “C/C++ IntelliSense and then Click on the Install button to install it.

Running C/C++ Program

Now that we’ve set up everything required to write and run C/C++ in windows, let’s run a simple hello.c program in our windows.

To run a C/C++ program first we need to compile it using gcc. So to compile your C/C++ code type gcc and then the file name of your code in terminal and hit enter. In my case to compile hello.c code I need to type gcc hello.c in my terminal.

gcc <file-name> #To compile code
gcc hello.c

It will take a few seconds to compile after it is done you’ll see a new file with the .exe extension. In my case it was a.exe, this exe file is your compiled code. Now to run the code type ./ and the file name in the terminal. So In my case, I need to type ./a.exe to run my code and then I’ll see the results.

example to run c/c++ programs in windows


So this is how you can set up C/C++ in Windows PC to write and run C/C++ code. If you are stuck somewhere whether in setting up MinGW or running C/C++ code watch my YouTube video given below to understand it.

YouTube player
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x