How to Run C Program in VS Code on Windows, Mac and Linux

To run C programs in VS Code, you need three things: VS Code, a C compiler and the C/C++ extension. On Windows, you can install the GCC compiler through MSYS2 (MinGW-w64); on macOS, you can use Clang through Xcode Command Line Tools; on Linux, you can install GCC through your package manager. After installing the compiler, you can write your code in a .c file, compile it with gcc and run it from the VS Code terminal. However, VS Code is only a code editor, so it cannot run C programs without a compiler.
authorImageVarun Saharawat1 Dec, 2026
C Programming in VS Code

Visual Studio Code, usually called VS Code, is one of the most popular code editors among students and developers. It is free, lightweight and works on Windows, macOS and Linux.

If you are learning C programming, VS Code can be a useful place to write, run and debug your programs. However, unlike some IDEs, VS Code does not include a C compiler by default. You need to set up a few tools before you can run your first program.

In this article, you will learn how to set up C programming in VS Code, run your first program, debug your code and fix common errors.

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

Before you begin, make sure you have the following:

Requirement Purpose
VS Code Code editor where you write your programs
C compiler (GCC or Clang) Converts your C code into a program your computer can run
C/C++ extension by Microsoft Adds code suggestions, error highlighting and debugging support
Code Runner extension (optional) Lets you run a program with one click

VS Code helps you write and manage code, while the compiler turns that code into an executable program. Both are required.

How to Set Up C Programming in VS Code on Windows?

Windows does not include a C compiler, so you need to install one first. A common option is GCC through MSYS2.

1. Install VS Code

Follow these steps:

1.     Download VS Code from the official Visual Studio Code website.

2.     Run the installer and keep the default settings.

3.     Select the option to add VS Code to PATH, if shown.

4.     Open VS Code after the installation is complete.

2. Install the GCC Compiler Using MSYS2

Follow these steps:

1.     Download and install MSYS2 from its official website.

2.     Open the MSYS2 UCRT64 terminal.

3.     Run the command: pacman -S mingw-w64-ucrt-x86_64-gcc

4.     Press Enter to confirm the installation.

3. Add the Compiler to PATH

Windows needs to know where the compiler is installed.

1.     Search for Environment Variables in the Start menu.

2.     Open Edit the system environment variables.

3.     Select Environment Variables, then select Path under User variables.

4.     Add the folder where gcc.exe is installed, usually C:\msys64\ucrt64\bin.

5.     Save the changes and restart VS Code.

4. Check the Installation

Open Command Prompt and run: gcc --version

If the installation is successful, you will see the GCC version number. If you see an error, check the PATH setting again.

How to Set Up C Programming in VS Code on macOS and Linux?

The setup is usually simpler on macOS and Linux.

macOS

1.     Open Terminal.

2.     Run: xcode-select --install

3.     Follow the prompts to install Xcode Command Line Tools.

4.     Check the installation with: clang --version

Linux (Ubuntu or Debian)

1.     Open Terminal.

2.     Run: sudo apt update

3.     Run: sudo apt install build-essential gdb

4.     Check the installation with: gcc --version

How to Install the C/C++ Extension in VS Code?

The C/C++ extension by Microsoft adds features such as IntelliSense, code navigation and debugging.

1.     Open VS Code.

2.     Select the Extensions icon in the left sidebar, or press Ctrl+Shift+X.

3.     Search for C/C++.

4.     Select the extension published by Microsoft.

5.     Select Install.

You may also install the Code Runner extension if you want to run programs with a single click. However, Code Runner shows output in the Output panel by default, which does not accept keyboard input. If your program uses scanf, enable the Run In Terminal setting in Code Runner.

How to Write and Run Your First C Program in VS Code?

Once the setup is complete, you can create and run your first program.

1. Create a Project Folder

Create a new folder, for example C-Programs, then open it in VS Code using File and Open Folder.

2. Create a C File

Create a new file and name it hello.c. Make sure the file ends with .c.

3. Write the Program

Type the following code:

#include <stdio.h>

int main() {

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

return 0;

}

4. Compile and Run the Program

Open the terminal in VS Code by selecting Terminal and New Terminal. Then run:

1.     Compile: gcc hello.c -o hello

2.     Run on Windows: .\hello.exe

3.     Run on macOS or Linux: ./hello

If everything is set up correctly, the terminal will display Hello, World!

Writing your first program is only the beginning. Practise with more examples in our C programming examples guide.

How to Debug a C Program in VS Code?

Debugging helps you find errors by running your program line by line.

1.     Open your .c file.

2.     Click to the left of a line number to add a breakpoint.

3.     Select Run and Debug from the left sidebar, or press F5.

4.     Choose the C/C++: gcc build and debug active file option when prompted.

5.     Use the controls to step through the code and check variable values.

VS Code creates a tasks.json and launch.json file in a .vscode folder to save these settings for your project.

Common Errors When Running C in VS Code and How to Fix Them

Error Likely cause How to fix it
gcc is not recognised as an internal or external command Compiler not installed or not added to PATH Install GCC and add its bin folder to PATH, then restart VS Code
#include errors detected VS Code cannot find the compiler or header files Select the correct compiler path in C/C++ settings
Program does not accept input Running in the Output panel Run the program in the terminal or enable Run In Terminal in Code Runner
Permission denied Running the program without execute permission on macOS or Linux Compile again or run chmod +x on the file
Old output appears Program not recompiled after changes Save the file and compile again before running

Useful VS Code Shortcuts for C Programming

Action Windows / Linux macOS
Open terminal Ctrl + ` Cmd + `
Save file Ctrl + S Cmd + S
Start debugging F5 F5
Format code Shift + Alt + F Shift + Option + F
Command Palette Ctrl + Shift + P Cmd + Shift + P
Comment a line Ctrl + / Cmd + /

Is VS Code Good for Learning C Programming?

VS Code can be a good choice for learning C because it is free, lightweight and widely used in the industry. Learning to compile programs from the terminal can also help you understand how C code becomes an executable program.

However, the initial setup can take some time for beginners. If you only want to test small programs quickly, an online C compiler may be easier at first. Once you are comfortable, VS Code can help you work on larger projects.

Once you can run programs comfortably, build your skills with our C program for pattern examples and the top C project ideas for beginners.

Start Writing C Programs in VS Code

Setting up C programming in VS Code requires a compiler, the C/C++ extension and a few configuration steps. Once the setup is complete, you can write, compile, run and debug C programs from one place.

Start with simple programs, practise regularly and learn to read compiler errors. These habits can help you build a strong foundation in C and prepare for more advanced programming. Strengthen your basics further with our C programming guide.

 

FAQs

Can I run C programs in VS Code without a compiler?

No. VS Code is a code editor, so you need a C compiler such as GCC or Clang to compile and run C programs.

Why does VS Code show "gcc is not recognised"?

This usually means GCC is not installed or its bin folder has not been added to the PATH environment variable. Add the folder to PATH and restart VS Code.

Why can't my C program take input in VS Code?

If you run the program in the Output panel, it cannot accept input. Run it in the terminal or enable the Run In Terminal setting in Code Runner.

Is VS Code better than Turbo C for learning C?

VS Code uses modern compilers that follow current C standards, while Turbo C is outdated. For most learners, VS Code or another modern IDE is a better choice.

Is VS Code free?

Yes. VS Code is a free code editor available for Windows, macOS and Linux.
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
Email Id
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