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
🌐
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
I installed VSC and wrote this program #include int main( void ) { printf("Hello world!"); } Then I installed a C/C++ debugger and I saved the file on the desktop as...
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
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 do I set up Visual Studio Code to compile and run C code? - Stack Overflow
I really like Microsoft's Visual Studio Code editor and I wonder how to configure it to compile and run C code. More on stackoverflow.com
🌐 stackoverflow.com
How do I compile and run?
Like the other comment states, I also use the terminal. For C, I used 'make filename.c' to compile. Then 'run filename' to run the executable file. For Python, i use 'python filename.py' since you don't need to complie More on reddit.com
🌐 r/vscode
12
6
September 4, 2024
C programming in Visual Studio - Stack Overflow
Can I use Visual Studio to learn C programming? In the new project menu I can choose between Visual Basic, Visual C#, Visual C++, Visual F# and others but I don't see "C" or "Visual C". More on stackoverflow.com
🌐 stackoverflow.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 your program's source code must be translated (compiled) before it can be run 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.
🌐
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 - This is how you can run any C/C++ program from VS Code/Insiders · It will compile and then run the code directly. After running a code, the code runner button would be set default to run directly. So, your computer is 100% ready for compiling and running any C/C++ programming code.
🌐
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 - Configure Compiler in VS Code: Open the VS Code settings, navigate to the C/C++ configurations, and set the "compilerPath" to the path of the installed C++ compiler. Create a New C File: Open VS Code, create a new C file with a .c extension, ...
🌐
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 - You can see in the image above the exact command is being executed in order to compile and run our code. 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 following the next steps:
Find elsewhere
🌐
HackerNoon
hackernoon.com › how-to-compile-cc-code-in-vs-code-windows-gy4l35g1
How to Compile C/C++ Code in VS Code (Windows) | HackerNoon
March 16, 2021 - How to Compile C/C++ Code in VS Code (Windows): To compile C/C++ code we need GCC/G++ to compile the code but Windows doesn't have a terminal.
🌐
GitHub
gist.github.com › akanshgulati › 56b4d469523ec0acd9f6f59918a9e454
Visual Studio Code task to compile and run C programs · GitHub
Note: Make sure you select the tab having C program as below tasks run on active tab in VS Code. { "version": "2.0.0", "tasks": [ { "label": "compile and run C", "type": "shell", "command": "gcc ${file} -o ${fileBasenameNoExtension} && ./${fileBasenameNoExtension} ", "presentation": { "reveal": "always", "panel": "shared" }, "group": { "kind": "build", "isDefault": true } } ] } ... Isn't it possible to have 2 different task files so that you can have 2 different keybindings assigned to them and run build task and run task separately?
🌐
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.
🌐
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 - ... Install C/C++ Extension: Open VS Code, go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or press Ctrl+Shift+X, and search for "C/C++".
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
C/C++ Compile Run - Visual Studio Marketplace
April 3, 2026 - Extension for Visual Studio Code - Easily compile, run, and debug single C/C++ files in VS Code.
🌐
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?

🌐
Visual Studio Code
code.visualstudio.com › docs › cpp › config-msvc
Configure VS Code for Microsoft C++
November 3, 2021 - If you have g++ or WSL installed, you might need to change compilerPath to match the preferred compiler for your project. For Microsoft C++, the path should look something like this, depending on which specific version you have installed: "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe".
🌐
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...
🌐
Quora
quora.com › How-do-I-compile-and-run-C-in-Visual-Studio-Code
How to compile and run C++ in Visual Studio Code - Quora
Add the compiler bin folder (e.g., C:\msys64\mingw64\bin or C:\Program Files\Microsoft Visual Studio...VC\Tools\MSVC...\bin) to PATH. macOS: Install Xcode Command Line Tools: xcode-select --install. Linux: Install gcc/g++: sudo apt install build-essential (Debian/Ubuntu) or equivalent. Install Visual Studio Code...