To run a C program in Visual Studio Code, follow these steps:

  1. Install the C/C++ Extension: Ensure you have the C/C++ extension installed in Visual Studio Code. You mentioned you have this set up, which is great.
  2. Set Up a Workspace: Create a new folder for your C projects. Open Visual Studio Code and select File > Open Folder... to open your newly created folder.
  3. Create a C File: Inside your workspace folder, create a new file with a .c extension (e.g., hello.c). You can do this by right-clicking in the Explorer pane and selecting New File.
  4. Write Your Code: Write your C code in the newly created file. For example:
       #include 
       
       int main() {
           printf("Hello, World!\n");
           return 0;
       }
    
  5. Configure Build Tasks: You need to set up a build task to compile your C code. Press Ctrl + Shift + B to open the build tasks menu. If prompted, select Create tasks.json file from template and choose Others. Modify the generated tasks.json file to include the following:
       {
           "version": "2.0.0",
           "tasks": [
               {
                   "label": "build",
                   "type": "shell",
                   "command": "gcc",
                   "args": [
                       "-g",
                       "${file}",
                       "-o",
                       "${fileDirname}/${fileBasenameNoExtension}"
                   ],
                   "group": {
                       "kind": "build",
                       "isDefault": true
                   },
                   "problemMatcher": [
                       "$gcc"
                   ],
                   "detail": "Generated task by gcc"
               }
           ]
       }
    
  6. Build Your Program: Press Ctrl + Shift + B again to build your program. This will compile your C code and create an executable in the same directory.
  7. Run Your Program: Open the terminal in Visual Studio Code (View > Terminal or `Ctrl + ``) and run your program by typing:
       ./hello
    
    (Replace hello with the name of your executable if different.)
  8. Debugging: To debug your program, you will need to set up a launch configuration. Go to the Run view (left sidebar) and click on create a launch.json file. Choose C/C++: g++ build and debug active file. This will create a launch.json file where you can configure debugging settings.
  9. Start Debugging: Set breakpoints in your code by clicking in the gutter next to the line numbers. Then, press F5 to start debugging your program.

By following these steps, you should be able to set up Visual Studio Code for C programming and run your code successfully.


References:

  • Walkthrough: Compile a C program on the command line
Answer from AI answer on learn.microsoft.com
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › cpp
C/C++ for Visual Studio Code
November 3, 2021 - C++ is a compiled language meaning ... on your computer. The C/C++ extension doesn't include a C++ compiler or debugger, since VS Code as an editor relies on command-line tools for the development workflow....
🌐
Reddit
reddit.com › r/c_programming › what tools do you use with visual studio code to run c code ?
r/C_Programming on Reddit: What tools do you use with Visual studio code to run C code ?
July 29, 2022 -

I followed what is said on this blog post, it takes so much time to run(or build) and sometimes just doesn't.

i've been using CodeBlocks before but didn't get comfortable with it i just don't like, it would be great if i can use VSC.

Edit: i use Windows.

c With visual studio code Nov 4, 2021
r/C_Programming
5y ago
How to properly set up a C project in vs code Nov 12, 2023
r/cprogramming
2y ago
how to use C on vscode Mar 7, 2023
r/learnprogramming
3y ago
More results from reddit.com
🌐
Medium
medium.com › @ochwada › c-programing-setup-in-visual-studio-code-bd4cb60e58ff
C Programming — Setup in Visual Studio Code | by Ochwada | Medium
November 16, 2024 - HEADER_H is a macro that is defined when the header is included for the first time, so if the file is included again, the content between #ifndef and #endif is ignored. ... This defines a macro PI with the value 3.14159, representing the mathematical constant π. This value can be used throughout the program wherever PI is referenced.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
C/C++ - Visual Studio Marketplace
Extension for Visual Studio Code - C/C++ IntelliSense, debugging, and code browsing.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-write-and-run-c-cpp-code-on-visual-studio-code
How to Write And Run C and C++ Code in Visual Studio Code
January 20, 2023 - Simply open VS Code/VS Code Insiders, open any folder, and create any file with the extension .c for the C file and .cpp for the C++ file. After writing your code, you can run the code directly using the play button you'll find in the upper ...
🌐
PW Skills
pwskills.com › blog › cpp › c-programming-in-vs-code
Can I Use C Programming in VS Code? Explained in Detail!
October 30, 2025 - One popular choice is the Microsoft C++ compiler, which is included in the Visual Studio Build Tools or Visual Studio IDE on Windows. Here are some steps to set up a C++ compiler for VS Code:
🌐
Kodersolution
kodersolution.com › home › articles › how to set up c programming in vs code on windows 11 and linux (gcc & mingw)
C Programming in VS Code (Windows 11 & Linux GCC Setup) | Kodersolution
September 30, 2026 - Complete step-by-step guide to configuring C development in VS Code. Install GCC via MinGW-w64 or build-essential, configure tasks.json, launch.json, and debug with GDB.
Find elsewhere
Top answer
1 of 1
5

To run a C program in Visual Studio Code, follow these steps:

  1. Install the C/C++ Extension: Ensure you have the C/C++ extension installed in Visual Studio Code. You mentioned you have this set up, which is great.
  2. Set Up a Workspace: Create a new folder for your C projects. Open Visual Studio Code and select File > Open Folder... to open your newly created folder.
  3. Create a C File: Inside your workspace folder, create a new file with a .c extension (e.g., hello.c). You can do this by right-clicking in the Explorer pane and selecting New File.
  4. Write Your Code: Write your C code in the newly created file. For example:
       #include 
       
       int main() {
           printf("Hello, World!\n");
           return 0;
       }
    
  5. Configure Build Tasks: You need to set up a build task to compile your C code. Press Ctrl + Shift + B to open the build tasks menu. If prompted, select Create tasks.json file from template and choose Others. Modify the generated tasks.json file to include the following:
       {
           "version": "2.0.0",
           "tasks": [
               {
                   "label": "build",
                   "type": "shell",
                   "command": "gcc",
                   "args": [
                       "-g",
                       "${file}",
                       "-o",
                       "${fileDirname}/${fileBasenameNoExtension}"
                   ],
                   "group": {
                       "kind": "build",
                       "isDefault": true
                   },
                   "problemMatcher": [
                       "$gcc"
                   ],
                   "detail": "Generated task by gcc"
               }
           ]
       }
    
  6. Build Your Program: Press Ctrl + Shift + B again to build your program. This will compile your C code and create an executable in the same directory.
  7. Run Your Program: Open the terminal in Visual Studio Code (View > Terminal or `Ctrl + ``) and run your program by typing:
       ./hello
    
    (Replace hello with the name of your executable if different.)
  8. Debugging: To debug your program, you will need to set up a launch configuration. Go to the Run view (left sidebar) and click on create a launch.json file. Choose C/C++: g++ build and debug active file. This will create a launch.json file where you can configure debugging settings.
  9. Start Debugging: Set breakpoints in your code by clicking in the gutter next to the line numbers. Then, press F5 to start debugging your program.

By following these steps, you should be able to set up Visual Studio Code for C programming and run your code successfully.


References:

  • Walkthrough: Compile a C program on the command line
🌐
Medium
medium.com › @hasanmcse › step-by-step-guide-to-develop-c-c-program-using-vs-code-faef2bb88995
Step-by-Step Guide to Develop C/C++ Program Using VS Code | by Engr. Md. Hasan Monsur | Medium
January 9, 2026 - A clear beginner-focused guide to developing C/C++ programs using VS Code, highlighting how it improves productivity compared to older IDEs…
🌐
DEV Community
dev.to › narottam04 › step-by-step-guide-how-to-set-up-visual-studio-code-for-c-and-c-programming-2021-1f0i
[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. - DEV Community
August 5, 2021 - In this blog post you will learn how to set up visual studio code on your local environment for C and C++, this can get tricky but if you follow step by step you can set it up easily. Type vscode on your browser and click on the first link of the page, or just click here.
🌐
Reddit
reddit.com › r/c_programming › guys who can explain me how to install c in vs code?
r/C_Programming on Reddit: guys who can explain me how to install C in VS code?
October 31, 2025 - I think understanding the terminology is very important. The difference between VS Code, C, and a C compiler is important foundational knowledge. I was just trying to provide the most helpful answer I know how. I’m sorry it wasn’t to your liking, but it wasn’t for you anyways.
🌐
YouTube
youtube.com › watch
How to Setup C/C++ in VS Code [Updated 2025] Complete Installation with example | Amit Thinks - YouTube
Learn how to setup and run C/C++ on VS Code. We will also run an example C file after the setup.C Tutorial (English): https://youtu.be/CobHIiQXMtQC Tutorial ...
Published: January 15, 2025
🌐
DEV Community
dev.to › haythammostafa › run-c-code-in-visual-studio-code-2j86
Run C Code in Visual Studio Code - DEV Community
July 3, 2023 - 8) As we click on the Continue, it shows the below image. In the MinGW Installation Manager, we need to check the Mingw32-base package, Ming32-gcc-g++ package and Ming32-gcc-objc package to run and compile the C/ C++ program in the visual studio code.
Top answer
1 of 2
3

The guide for using C++ with Visual Studio Code is located here:

  • C/C++ for Visual Studio Code

If you are using the windows operating system, you can install the Microsoft Visual C++ (MSVC) compiler toolset as described here:

  • Configure VS Code for Microsoft C++

Otherwise you should read the tutorials for the compiler you want to use:

  • Tutorials for other compilers

The reason I refer to links, instead of explaining the details here, is because the answer might become outdated/obsolete. Sometimes links are better than explanations.

2 of 2
2

Step 1. Download the MinGW - Minimalist GNU for Windows at SourceForge, link here.

When you download Minimalist GNU for Windows (MinGW), you can choose which packages to install. You should select the following packages:

  • mingw-developer-toolkit
  • mingw32-base
  • mingw32-gcc-g++
  • msys-base

Then click on the Installation tab on the top left and click on Apply Changes.

After installation, go to your C Drive where the MinGW is installed, and enter the folders MinGW > bin. Copy the path C:\MinGW\bin

Now search for environment, and enter edit environment variables for your account. screenshot

Next, double-click on Path, click on New, paste the path C:\MinGW\bin, press enter, and click OK.

Verify that it has been installed correctly by opening up Command Prompt and typing in gcc --version. It should give you the current version number.

Step 2. In Visual Studio Code, click on the Extensions tab, search and install Code Runner by Jun Han

Step 3. In the C/C++ Configurations. Make sure the Compiler Path has c:/MinGW/bin/gcc.exe selected. screenshot 2

You can get to it by opening Command Pallet (ctrl+shift+p) typing in C/++: Select a Configuration.. then select Edit Configurations (UI)

🌐
Reddit
reddit.com › r/c_programming › c in visual studio code
r/C_Programming on Reddit: C in Visual Studio Code
April 26, 2024 -

I want to practice C in Visual Studio Code (mac). I was already prompted to download a bunch of add ons for C and other languages such as CSS and HTML.

I wrote my code and tried to run the executable in the terminal but apparently I need to download the "command line developer tools" package. I had to stop myself because it requires a whopping 15.6 GB of disk space while the program itself is only 580 mb. How can this be if there are sandbox programs which you can code in on your browser? As far as I understood people have been coding in c since a hard drive of 512 mb was considered big...