Physics Wallah

How to Run C Programs in VS Code: A Step-by-Step Guide

To run a C program in VS Code, you need to install a C compiler such as MinGW (GCC) separately, add its bin folder to your Windows PATH and install the C/C++ extension in VS Code. After setup, create a .c file, compile it and run the executable through the terminal or use the Code Runner extension.
authorImageAvisha Das20 Nov, 2026
Prefer as Trusted Source on Google

Clicking will open your Google Search settings to set PW as a preferred source

How to Run C Programs in VS Code: A Step-by-Step Guide

You have written your first C program, but clicking the Run button does nothing. Or perhaps VS Code displays an error saying that the compiler command is not recognised. If this sounds familiar, the problem may not be your code at all.

Visual Studio Code is a code editor, not a compiler. It provides a place to write and manage code, but you need a separate compiler to convert your C program into an executable file. Once you install and configure the compiler, running C code in VS Code becomes much easier. Here is how to set up VS Code, install MinGW on Windows, create your first C file and run it using the terminal. 

What Do You Need to Run C Code in VS Code?

Before writing your first program, make sure you have an editor, a compiler and the required system settings.

You need three things to run a C program in Visual Studio Code:

  • Visual Studio Code: The editor where you write and manage your C programs.

  • A C compiler: MinGW, which provides GCC, is one option for Windows users. It converts C source code into an executable program.

  • Compiler added to PATH: This allows Windows to recognise commands such as gcc from the terminal.

You can download VS Code without installing a compiler, but you will not be able to compile and execute C programs until a compiler is available.

Step 1: Install MinGW on Windows

MinGW provides the GCC compiler required to compile your C program on Windows.

Follow these steps to install it:

  1. Search for the official MinGW download page and download the installer.

  2. Open the downloaded installer and click Install.

  3. Once the installation manager opens, select the packages required for C compilation, including the GCC compiler.

  4. Apply the changes and allow the required files to download.

  5. Wait for the installation to finish.

The compiler files are generally available inside the MinGW installation folder. You will need the location of its bin folder in the next step.

Confused about how GCC turns your .c file into an executable? Learn the complete C compilation process. 

Step 2: Download and Install Visual Studio Code

Install VS Code separately because the editor and compiler perform different jobs.

  1. Visit the official Visual Studio Code website.

  2. Download the Windows installer suitable for your system.

  3. Open the installer and accept the licence agreement.

  4. Follow the installation instructions. You can keep the default settings.

  5. Select options such as adding VS Code to PATH, if available.

  6. Complete the installation and launch VS Code.

Once the editor opens, you can configure it to work with the compiler installed earlier.

Step 3: Add MinGW to the Windows PATH

Adding the MinGW bin folder to PATH allows the terminal to find GCC without requiring its full location every time.

Here is how you can do it:

  1. Open File Explorer and locate the MinGW installation folder.

  2. Open its bin folder and copy the folder address from the address bar.

  3. Search for Edit the system environment variables in Windows Search.

  4. Open the option and click Environment Variables.

  5. Under the available variables, select Path and click Edit.

  6. Click New, paste the copied MinGW bin folder address and confirm the changes.

  7. Click OK to close the open settings windows.

For example, your compiler path may look like C:\MinGW\bin, depending on where you installed MinGW.

Close and reopen VS Code after updating PATH so that its terminal can recognise the new setting.

Step 4: Set Up VS Code for C Programming

Install the relevant extensions to make writing and running C code easier.

Open VS Code and select the Extensions icon from the sidebar. Search for and install:

  • C/C++ by Microsoft: Provides code completion, syntax support and error highlighting for C and C++.

  • Code Runner: Adds a convenient option to execute code from the editor.

You can also open Code Runner settings and enable Run In Terminal. This is particularly useful when your C program requires user input.

Save your settings and keep VS Code open for the next step.

Step 5: Create Your First C Program in VS Code

Create a folder, open it in VS Code and save your program with the .c extension.

Follow these steps:

  1. Create a folder on your computer, such as C Programs.

  2. Open VS Code and select File > Open Folder.

  3. Choose the folder you just created.

  4. Click the New File icon and name the file hello.c.

  5. Enter the following C program:

#include <stdio.h>


int main(void) {

    printf("Hello, World!\n");

    return 0;

}
  1. Press Ctrl + S to save the file.

The .c extension identifies the file as a C source file. The program uses printf() to display the message and return 0 to indicate that it has finished successfully.

Want to understand the code before moving ahead? Read PW Skills' C Programming Foundations course.

Step 6: How to Run a C Program in VS Code

You can execute your program using the Code Runner button or compile and run it directly from the VS Code terminal.

Method 1: Use the Run Code Button

If you have installed the Code Runner extension:

  1. Open your hello.c file.

  2. Save the program using Ctrl + S

  3. Click Run Code at the top-right corner of the editor.

  4. Check the output in the terminal or output panel, depending on your settings.

You should see:

Hello, World!

Method 2: Run C Code in the VS Code Terminal

You can also compile and execute your program manually. This method helps you understand what happens when a C file is converted into an executable.

  1. Open the VS Code terminal using Ctrl + `

  2. Enter the following command:

gcc hello.c -o hello.exe
  1. Press Enter to compile the program.

  2. Run the generated executable using:

.\hello.exe

The first command uses GCC to compile hello.c and create an executable named hello.exe. The second command runs that executable.

If the terminal displays Hello, World!, your C program has run successfully.

Struggling to practise C after setting up VS Code? Watch this beginner-to-advanced C Language Full Course and solve 100+ questions step by step. 

How to Run C Programs in VS Code on Mac

Mac users need a compiler toolchain for macOS instead of following the Windows MinGW PATH steps.

You can use Apple's Command Line Tools to install the compiler tools:

  1. Open Terminal on your Mac.

  2. Run the command:

xcode-select --install
  1. Follow the installation instructions.

  2. Download and install the macOS version of Visual Studio Code.

  3. Install the C/C++ extension and create a file named hello.c.

  4. Open the VS Code terminal and compile the file:

clang hello.c -o hello
  1. Run the program:

./hello

The terminal should display Hello, World!. The same approach works on Apple Silicon and Intel Macs once the required compiler tools are installed.

If you want to practise C concepts alongside your setup, you can also watch PW's C Language Full Course 

Common Errors When Running C Code in VS Code

Most beginner errors are caused by compiler installation, PATH settings or incorrect file names.

Error or issue

What you can check

gcc is not recognised

Check whether the MinGW bin folder is added correctly to PATH. Restart VS Code after changing PATH.

No such file or directory

Check whether the terminal is open in the folder containing your .c file.

undefined reference

Review your code for missing function definitions or incorrect compilation commands.

No output appears

Save the file, check the terminal and confirm that the program contains a working output statement.

Code Runner does not execute the program

Check the extension settings and confirm that the compiler is installed and available.

If the error continues, try compiling the file manually through the terminal. This can help you identify whether the issue is with the compiler setup or the editor extension.

Key Takeaways

  • VS Code is a code editor, so you need a separate C compiler such as MinGW on Windows.

  • Add the compiler's bin folder to the Windows PATH so the terminal can recognise GCC.

  • Install the C/C++ extension and, optionally, Code Runner to make coding easier.

  • Save your program with a .c extension before compiling it.

  • Use gcc hello.c -o hello.exe to compile a Windows C program and .\hello.exe to run it.

  • Mac users can install Apple's Command Line Tools and use Clang to compile and execute C programs.

Running a C program in VS Code becomes straightforward once the compiler and editor are configured correctly. Install MinGW on Windows, update the PATH, add the required extensions and test your setup with a simple Hello, World! program.

Once your first program runs, keep practising with variables, loops, functions and other C concepts. You can also explore PW Skills programming and DSA courses to build on your programming fundamentals and move towards problem-solving with other languages.

FAQs

1. How to run C code in VS Code?

Install a C compiler such as MinGW, add its bin folder to PATH and install the C/C++ extension in VS Code. Create a .c file, write your program, save it and compile it through the terminal or use Code Runner.

2. How to run a C program in Visual Studio Code without Code Runner?

You do not need Code Runner to execute C programs. Open the integrated terminal, compile your file using gcc filename.c -o filename.exe and run it using .\filename.exe on Windows.

3. How to run a C file in VS Code terminal?

Open the folder containing your C file in VS Code and launch the integrated terminal. Enter gcc filename.c -o filename.exe to compile it, followed by .\filename.exe to execute it on Windows.

4. C Programming Bhasha Ka Aavishkar Kisne Kiya Tha?

C programming language was developed by Dennis Ritchie at Bell Laboratories in the early 1970s. It became widely used for system programming and influenced several later programming languages.
avatar

Get Free Counselling Today

and Clear up all your Doubts

Talk to Our Counsellor just by filling out the form.
Student Name
Phone Number
IN
+91
OTP
Join 15 Million students on the app today!
Point IconLive & recorded classes available at ease
Point IconDashboard for progress tracking
Point IconLakhs of practice questions
Download ButtonDownload Button
Banner Image
Banner Image
Free Learning Resources
Know about Physics Wallah
Physics Wallah is an Indian edtech platform that provides accessible & comprehensive learning experiences to students from Class 6th to postgraduate level. We also provide extensive NCERT solutions, sample paper, NEET, JEE Mains, BITSAT previous year papers & more such resources to students. Physics Wallah also caters to over 3.5 million registered students and over 78 lakh+ Youtube subscribers with 4.8 rating on its app.
We Stand Out because
We provide students with intensive courses with India’s qualified & experienced faculties & mentors. PW strives to make the learning experience comprehensive and accessible for students of all sections of society. We believe in empowering every single student who couldn't dream of a good career in engineering and medical field earlier.
Our Key Focus Areas
Physics Wallah's main focus is to make the learning experience as economical as possible for all students. With our affordable courses like Lakshya, Udaan and Arjuna and many others, we have been able to provide a platform for lakhs of aspirants. From providing Chemistry, Maths, Physics formula to giving e-books of eminent authors like RD Sharma, RS Aggarwal and Lakhmir Singh, PW focuses on every single student's need for preparation.
What Makes Us Different
Physics Wallah strives to develop a comprehensive pedagogical structure for students, where they get a state-of-the-art learning experience with study material and resources. Apart from catering students preparing for JEE Mains and NEET, PW also provides study material for each state board like Uttar Pradesh, Bihar, and others

Copyright © 2026 Physicswallah Limited All rights reserved.