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
C in Visual Studio Code Apr 26, 2024
r/C_Programming
2y ago
how to use C on vscode Mar 7, 2023
r/learnprogramming
3y ago
More results from reddit.com
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
C/C++ - Visual Studio Marketplace
Extension for Visual Studio Code - C/C++ IntelliSense, debugging, and code browsing.
๐ŸŒ
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.
๐ŸŒ
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:
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
๐ŸŒ
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 ...
Find elsewhere
๐ŸŒ
Kodersolution
kodersolution.com โ€บ home โ€บ articles โ€บ c programming in vs code: complete gcc setup guide
C Programming in VS Code: Complete GCC Setup Guide | Kodersolution
September 30, 2026 - Learn how to configure C programming in VS Code step-by-step using GCC (MinGW-w64), build tasks.json, set up GDB debugging, and fix common PATH errors.
๐ŸŒ
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 - Showcase: I created Install C - Fast and Simple One-Click Installer for the entire C development toolchain. ... C with VsCode, I want to learn C on visual code and Iโ€™m a noob, which extension have I to install, in order that my code works, and the steps to make it work, ty for your help
๐ŸŒ
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.
๐ŸŒ
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)

๐ŸŒ
GitHub
gist.github.com โ€บ hans-jorg โ€บ f12214e1738b687da60d492c0077692e
VS Code for C Development including for Embedded Systems ยท GitHub
VS Code uses JSON configuration files in the (hidden in Linux systems) folder, called .vscodes. tasks.json: It instructs VS Code how to compile and build the executable. launch.json: It instruct VS Code how to run and/or debug the executable. c_cpp_properties.json: configures Intelisense for C/C++ files.