How To Run C in Visual Studio Code on Windows 11
Setting up a C development environment on Windows 11 can be a time-consuming and frustrating process, especially if you are new to development or working with a new language or framework. We will first go over the basics of installing a C compiler and setting up a C development environment in Windows 11. We will then show you how to create a simple C program and how to run C in Visual Studio Code on Windows 11.
Video Tutorial: How To Run C in Visual Studio Code on Windows 11
Step 1: Download the C Compiler for Windows 11
1. We need to download the C compiler for the Windows 11 machine. We’re going to download the “MinGW GCC ” compiler. Click on the below link to open the download page for MinGW Compiler.
Download MinGW Compiler Link: https://techdecodetutorials.com/download/
2. We will be downloading a self-extractable archive for MinGW to make the installation process easy. So we will click on the “Direct Download Link” and the download will start.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-1-1024x443.png)
Step 2: Extract Zip File
1. Once it has been downloaded, you need to open it from the folder and then double-click on it to start the installation process.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-2-1024x637.png)
2. Choose the extraction location of the compiler by typing “C:\” in the text field and then click the extract button to start the extraction process. The extraction of this archive will take some time.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-3-1024x576.png)
Step 3: Set Up Environment Variables
1. First, copy the location of the bin folder from the newly extracted MinGW directory. In our case, it looks like this: “C:\MinGw\bin“. Next, we will set up the environment variables for accessing gcc in vscode.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-5-1024x576.png)
2. Now click on the Windows button and then type Environment Variables in the search field and press Enter
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-4-1024x576.png)
3. Click on the Environment Variable
button.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-6-1024x576.png)
4. Now, select the Path
variable and click on the Edit
button.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-7-1024x576.png)
5. Click the "New"
button, then paste the following location in the blank field and click "OK."
Location: C:\MinGw\bin
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/clipboard-1024x930.png)
Step 4: Check Verify G++ Version
1. To check if the MinGW compiler
is working properly, open windows command prompt by pressing the Windows button and type cmd, then press enter.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-8-1024x576.png)
2. In the command prompt type, gcc --version
and press enter key to check the installed version of MinGW gcc
.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-23.png)
Step 5: Install C/C++ Extensions in Visual Studio Code on Windows 11
Also Read: How To Install Visual Studio Code in Windows 11
1. Open visual studio code, Press Windows keys and then type Visual Studio Code
and press enter.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-10-1024x576.png)
2. Click on the extension button and in the search bar type C/C++
, then select the first option from Microsoft and click on the small blue install button.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-11.png)
3. Now again in the extensions search bar type Code Runner
, select the first option from Jun Han
and click on the small install button.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-12-1024x576.png)
with this extension, you can easily run the code by pressing Ctrl+Alt+N and stop the code by pressing Ctrl+Alt+M
Step 6: Run C in Visual Studio Code on Windows 11
1. Now create a new file and save it as subscribe.c
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-24.png)
Make sure to add “.c” extension at the end of the filename as without it visual studio code won’t be able to detect the code as a c program
2. Paste the following code snippet and save your code by pressing Ctrl+S
#include<stdio.h> int main() { printf("Subscribe Now!"); return 0; }
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-25.png)
3. To run the C program you can press Ctrl+Alt+N or you can simply press the play button on the top right and you’ll see an output like the below image.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-15.png)
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-17-1024x282.png)
Step 7 [Bonus]: Fix Cannot Edit in reading Only Editor in Visual Studio Code
1. Create a new file in visual studio code and save it as an inputProgram.cpp
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-26.png)
2. Paste the following code snippet and save your code by pressing Ctrl+S
and run the code by pressing Ctrl+Alt+N
or run play button.
#include<stdio.h> int main() { char fname[20],lname[20]; printf("Enter your first name : "); scanf("%s",fname); printf("Enter your last name : "); scanf("%s",lname); printf("Your full name is %s %s",fname,lname); return 0; }
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-27-1024x775.png)
3. It will show the output but you will not be able to enter your first name
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-20-1024x186.png)
4. To fix this, Open settings by pressing Ctrl+
and in the search bar type Run In Terminal and hit enter. Now Scroll down a little bit and tick the Code Runner: Run in Terminal
checkbox.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-21-1024x576.png)
5. Now go back to the program we’ve created in step 2 and press Ctrl+Alt+N
this time you will be able to enter your first name and last name.
![](https://techdecodetutorials.com/wp-content/uploads/2022/07/image-22-1024x298.png)
Now start your journey in c++ programming
Click Here To Enroll in Complete C Programming Course: Go From Beginner to Master with an additional discount.
Click Here To Enroll in Complete C++ Programming Course: Go From Beginner to Beyond with an additional discount.