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...
🌐
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… More on learn.microsoft.com
🌐 learn.microsoft.com
1
1
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 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
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
🌐
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 - Find and select Run Code Configuration. Find and check the box Run in Terminal. ... Now our program will run in the TERMINAL tab and we will be able to enter data if we need to. And that’s it, following these steps you will be able to compile and run code in C/C++ using Visual Studio Code.
🌐
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.
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
Find elsewhere
🌐
PW Skills
pwskills.com › blog › cpp › c-programming-in-vs-code
Can I Use C Programming in VS Code? Explained in Detail!
Open Settings: Press Ctrl+, to open the Settings in VS Code. Navigate to C/C++ Configuration: In the Settings, search for "C/C++" and select "Edit in settings.json" under "C_Cpp: Edit Configurations (UI)". Configure Compiler Path: Set the ...
🌐
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.
🌐
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.
🌐
GitHub
gist.github.com › akanshgulati › 56b4d469523ec0acd9f6f59918a9e454
Visual Studio Code task to compile and run C programs · GitHub
Copy below configuration code and save it. Simple press Cmd + Shift + B to compile and run. Note: Make sure you select the tab having C program as below tasks run on active tab in VS Code.
🌐
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?

🌐
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 VS Code. Go to the Extensions view by clicking on the Extensions icon in the Activity Bar (or press Cmd+Shift+X). Search for C/C++ in the Extensions Marketplace. Click Install for the extension provided by Microsoft.
🌐
Quora
quora.com › How-can-I-compile-my-C-program-in-VS-Code-Ubuntu
How to compile my C program in VS Code Ubuntu - Quora
Answer (1 of 2): The compilation is quite simple 1. Use [code ]Ctrl+~[/code] to get the terminal of VS Code. 2. Navigate to the directory in which the source code is located. 3. simple [code ]gcc .c[/code] 4. Then: [code ]./a.out[/code]
🌐
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 - We have given step-by-step instructions on how to run/ execute a C program with and without an IDE and in the Visual Studio code editor (e.g., VSCode). A number of IDEs (Integrated Development Environments) are available for C language to type, compile, debug, and run C source code.
🌐
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...
🌐
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 - Visual Studio Code: Download and install Visual Studio Code. C Compiler: You need a C compiler installed on your system: Windows: Install MinGW. After installation, add the bin directory (e.g., C:\MinGW\bin) to your system's PATH.