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
Top answer
1 of 1
1

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
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)

Discussions

What tools do you use with Visual studio code to run C code ?
Im on windows.. Here i have for my setup I download C compiler from winlibs website, VSCode and then simply use make to compile and run my code.. As simple as that More on reddit.com
🌐 r/C_Programming
55
15
July 29, 2022
How to compile C program in Visual Studio Code? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
How do I make vs code put the output of my c program in TERMINAL panel? - Stack Overflow
I'm trying to build and run C code with vscode on windows 10. I've gone through the vscode doc for mingw configuration, followed the steps there and managed to run a .c file with vscode. However, ... More on stackoverflow.com
🌐 stackoverflow.com
Running a simple C program using VS code - Stack Overflow
I recently started taking a C course and I am having some difficulties running a simple I/O program: #include int main() { int age; printf("Please enter your age: &quo... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › cpp
C/C++ for Visual Studio Code
November 3, 2021 - To make sure the compiler is installed and configured correctly, lets create a Hello World C++ program. On Windows, launch a Windows command prompt (Enter Windows command prompt in the Windows search bar). On macOS and Linux, you can enter these commands in the terminal. Run the following commands.
🌐
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 - Scroll down a little bit until you find Code-runner: Run In Terminal. Make sure that the box is checked (✔). ... Now you need to restart your VS Code/VS Code Insiders. Simply close and reopen the program.
🌐
Quora
quora.com › How-can-I-run-a-C-program-in-a-Visual-Studio-Code
How to run a C program in a Visual Studio Code - Quora
Answer (1 of 8): * You should first go to option create a new project in file menu. * Then enter the name of project press OK and accept the defaults and press finish. * Then a new terminal is opened for you on the screen . * Then you should type a syntactically correct program. [code]For exa...
🌐
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 - 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. After selecting the checkbox, click on the Installation tab (at the top left corner of the dialog box). 9) Click on Apply Changes to set the package's installation in MinGW ... b. In the System Variables Path click on the Edit button, then click on the New button and then paste the C:\MinGW\bin path; after that, click OK · 13) Check C and C++ compilers again now, Open your terminal and run:
🌐
PW Skills
pwskills.com › blog › cpp › c-programming-in-vs-code
Can I Use C Programming in VS Code? Explained in Detail!
Build and Run: Use the integrated terminal to navigate to the directory containing your C file and use a command like gcc filename.c -o output && ./output to build and run the program.
Find elsewhere
🌐
Medium
medium.com › @yutung3397 › getting-started-how-do-i-run-a-program-in-visual-studio-code-15c6193c34b5
Getting Started — How do I run a program in Visual Studio Code? | by Michelle Cu | Medium
July 8, 2025 - { "version": "2.0.0", "tasks": ... } ] } For the output to appear in the terminal, first press shift+command+p to open the configuration palette, then click on Run Task ....
🌐
Medium
ludwiguer.medium.com › configure-visual-studio-code-to-compile-and-run-c-c-3cef24b4f690
Configure Visual Studio Code to compile and run C/C++ | by Luis Guerrero | Medium
April 6, 2020 - Until here everything seems fine, but since the OUTPUT tab is read-only, we cannot interact with our code if we need to. To be able to do so, we need to tell the extension Code Runner to run our program in the TERMINAL instead of the OUTPUT tab ...
🌐
Stack Overflow
stackoverflow.com › questions › 65598881 › how-to-compile-c-program-in-visual-studio-code
How to compile C program in Visual Studio Code? - Stack Overflow
Choose your newly installed compiler (GCC or Clang) from the prompt. It will compile the code and print "Hello world!" in the terminal at the bottom
🌐
Coding Campus
codingcampus.net › home › how to run a c or c++ program in vs code
How to run a C or C++ program in VS Code - Coding Campus
December 3, 2022 - This article will demonstrate the step-by-step process to get you started with running C and C++ in Visual Studio Code.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › build › walkthrough-compile-a-c-program-on-the-command-line
Compile a C Program on the Command Line | Microsoft Learn
There might be differences in the current directory or version numbers, depending on the version of Visual Studio and any updates installed. If the preceding output is similar to what you see, then you're ready to build C or C++ programs at the command line. ... If you get an error such as 'cl' is not recognized as an internal or external command, operable program or batch file, error C1034, or error LNK1104 when you run the cl command, then either you're not using a developer command prompt, or something is wrong with your installation of Visual Studio.
🌐
Unstop
unstop.com › home › blog › how to run c program | step-by-step guide + detailed examples
How To Run C Program | Step-by-Step Guide + Detailed Examples
September 16, 2024 - If you wish to run it without debugging, then press Ctrl + F5. The Visual Studio is a code editor which works like IDE and functions with any compiler that is installed on the system.
🌐
Medium
medium.com › @aleksej.gudkov › how-to-run-c-code-in-vs-code-on-mac-473980c24679
How to Run C Code in VS Code on Mac | by UATeam | Medium
November 24, 2024 - Open the integrated terminal in VS Code (Ctrl+`` ). Navigate to the directory containing your code. ... Hello, World! Running C code in VS Code on a Mac is straightforward with the right setup.
🌐
Reddit
reddit.com › r/vscode › how do i compile and run?
r/vscode on Reddit: How do I compile and run?
September 4, 2024 -

I’ve been programming for years now, in multiple languages. I’ve never used an IDE or anything like vs code. I usually just use a text editor and a terminal to do all my coding.

This whole process is starting to get annoying so I downloaded vs code but I cannot get anything to work. I don’t know what I am doing. According to the tutorials, I should be able to press the debug and run button and vs code will compile and run my code, but I can’t get this to work. It’s saying I need a configuration, or that blah blah blah.

So far, I’ve only been able to get python to work. So my questions are: what is a configuration? Why do I need one? How do I get c++ to work with the push of one button?

🌐
Reddit
reddit.com › r/c_programming › [deleted by user]
[deleted by user] : r/C_Programming
July 8, 2024 - If you have the time and want to ... some issues compiling until I ran VS Code from the developer prompt that comes with it. Just open the prompt and type code to launch the GUI....