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 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.
Discussions

how to run program in c in visual studio code
Hi, I am using visual studio code version 1.107.1 (user setup). for learning programing in "C" . I need help to setup studio code, to create workspace, file and run the debug . I have setup c/c++ , c/c++run extension. I have download gcc compiler and verified in cmd. More on learn.microsoft.com
🌐 learn.microsoft.com
2
3
How do I set up Visual Studio Code to compile and run C code? - Stack Overflow
Releases Keep up-to-date on features ... Stack Internal. ... The 2026 Annual Developer Survey Results Site is live— view the results here! Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... I really like Microsoft's Visual Studio Code editor and I wonder how to configure it to compile and run ... More on stackoverflow.com
🌐 stackoverflow.com
C programming in Visual Studio - Stack Overflow
Visual Studio 2013 has much better support for C than 2012. ... I have books and video tutorials but they all have their own recommendations when it comes to the tools used to compile and write the 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
11
6
September 4, 2024
🌐
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 - Before approaching the process of running your first C or C++ code on Visual Studio Code, let me guide you through the process and get it all set up based on the operating system you are using on your computer. For running C or C++ code, you just need to have a valid C/C++ compiler installed on your computer.
🌐
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
The build tools for Visual Studio install only the command-line toolset, the compilers, tools, and libraries you need to build C and C++ programs. It's perfect for build labs or classroom exercises and installs relatively quickly. To install only the command-line toolset, download build tools for Visual Studio from the Visual Studio downloads page and run the installer.
🌐
YouTube
youtube.com › codevault
Compile and run C code using Visual Studio Code (2020) - YouTube
Link to download the Visual Studio Code IDE and Visual C/C++ compiler: https://visualstudio.microsoft.com/downloads Check out our Discord server: https://dis...
Published: April 23, 2020
Views: 9K
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
🌐
YouTube
youtube.com › watch
How to Compile and Run C Code in Visual Studio Code - YouTube
Learn how to compile and run C program files directly inside Visual Studio Code. This guide walks you through the setup process so you can start coding immed...
Published: October 2, 2026
Find elsewhere
🌐
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 - Or we can open VSC, go to Code > Preferences > Extensions (also using the shortcut shift + cmd + X) type C++ and press install. ... The next extension is to actually compile and run our code, I picked Code Runner, we can download it from here, ...
🌐
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.
🌐
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?

🌐
YouTube
youtube.com › watch
How to Compile and Debug C code in Visual Studio Code - YouTube
0:00 Introduction0:22 Context3:03 Windows Installation4:54 Linux Installation5:33 macOS Installation6:26 Compilation8:15 Debugging9:55 Debugging Several File...
Published: June 16, 2026
🌐
Reddit
reddit.com › r/c_programming › easiest way to set up c compiler on windows 10 (if you use visual studio code)?
r/C_Programming on Reddit: Easiest way to set up C compiler on Windows 10 (if you use Visual Studio Code)?
March 8, 2023 -

I've been learning C and playing around with it for a couple of months already.

I'm following CS50 course and first half of the course is almost entirely in C.

That being said, I only used their online codespaces so far, - and for my own personal practice, I used online complilers such as https://www.programiz.com/c-programming/online-compiler/

and https://www.onlinegdb.com/online_c_compiler .

This allowed me to focus on coding and not worry about compiling. I've made some stuff already, entirely using these tools.

However, now arrives the time that I need my own compiler on local machine.

The main reason is that I want to start practicing working with files on my own hard disk, and also using libraries outside of what these tools offer, such as conio.h.

I already tried to google how to set-up a compiler in Windows, but I've bumped into many hoops and obstacles and it's not (at least for me) as straightforward as it might seem.

So I'm asking you for help to set up my own coding environment for C in Windows, where I could compile the files (ideally with make too, and not just clang), where I could include external libraries, where I could work with files on my own HDD, etc... And ideally, where I could even turn these files into classical .exe files.

Thanks!

EDIT: Resolved:

Installing Visual Studio 2022 Community with included tools for C++, and then running Developer Command Prompt allowed me to compile C files by using command: cl filename.c which returns exe file, filename.exe . This exe file can be started by simply executing filename in command prompt or even from Windows by simply double clicking on its icon, like any other file. Thanks for all the responses, especially to RidderHaddock and _mutaz_ who gave me best directions.

🌐
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, ...
🌐
3.0 University
3university.io › home › learn articles › how to compile and run a c program in vs code, terminal and turbo c++
How to Compile and Run a C Program in VS Code, Terminal and Turbo C++ - 3.0 University
August 31, 2026 - VS Code creates a .vscode/tasks.json file in your workspace. The key line in that file looks like this: “command”: “/usr/bin/gcc” (Linux/Mac) or “command”: “C:/MinGW/bin/gcc.exe” (Windows) Once saved, press Ctrl+Shift+B to build your active .c file. The compiled output appears ...
🌐
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.
🌐
YouTube
youtube.com › watch
How to Run C/C++ in Visual Studio Code (Complete Setup) - YouTube
In this video, I will show you How to Run C and C++ in Visual Studio Code — breaking it down step by step so you can follow along and use it in your own pro...
Published: September 12, 2026
🌐
freeCodeCamp
freecodecamp.org › news › how-to-compile-your-c-code-in-visual-studio-code
How to compile your C++ code in Visual Studio Code
September 10, 2024 - In this article, I'll show you how to set up your compiler in VsCode and give you some links to some of the best C++ resources. Prior knowledge of C++ (I assume you're learning C++, about to start learning, or just reading this for fun. This article is not a C++ 101 tutorial – some understanding of C++ is needed.) Visual Studio Code Editor Download here and read the setup docs for Windows, Linux and Mac