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.
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.
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.
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.
2. Now click on the Windows button and then type Environment Variables in the search field and press Enter
3. Click on the Environment Variable
button.
4. Now, select the Path
variable and click on the Edit
button.
5. Click the "New"
button, then paste the following location in the blank field and click "OK."
Location: C:\MinGw\bin
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.
2. In the command prompt type, gcc --version
and press enter key to check the installed version of MinGW gcc
.
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.
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.
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.
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
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; }
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.
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
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; }
3. It will show the output but you will not be able to enter your first name
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.
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.
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.