Here’s a step-by-step guide to run your first C program in Visual Studio Code (VS Code) using MinGW (Minimalist GNU for Windows).
🧰 Step 1: Install the Required Tools
1. Install MinGW
- Go to the official MinGW website:
👉 https://www.mingw-w64.org/ - Download the mingw-w64 installer (for your Windows version).
- Run the installer:
- Architecture:
x86_64(for 64-bit systems) - Threads:
posix - Exception:
seh - Installation directory:
C:\mingw-w64
- Architecture:
- Wait for installation to complete.
2. Add MinGW to System PATH
You need to make GCC (the C compiler) available from any terminal.
- Open Start Menu → Edit the system environment variables.
- Click Environment Variables.
- Under System variables, find
Path→ Edit → New. - Add:
C:\mingw-w64\bin - Click OK on all dialogs.
✅ Verify the installation:
Open Command Prompt and type:
gcc --version
You should see GCC version info (e.g., gcc (x86_64-posix-seh, Built by MinGW-W64 project)).
3. Install Visual Studio Code
If not installed yet, download and install:
👉 https://code.visualstudio.com/
4. Install C/C++ Extensions in VS Code
Open VS Code → Go to Extensions (Ctrl+Shift+X) → Search and install:
- C/C++ (by Microsoft)
- (Optional) Code Runner (to run C programs easily)
🧑💻 Step 2: Create and Run Your First C Program
1. Create a new folder
Example: C:\C_Programs\HelloWorld
2. Open it in VS Code
- In VS Code → File → Open Folder → select your folder.
3. Create a new file named:
hello.c
4. Write your first C program:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
⚙️ Step 3: Compile and Run the Program
Option 1: Use VS Code Terminal
- Open the terminal in VS Code:
Ctrl + ` - Compile the code:
gcc hello.c -o hello(This creates an executable file namedhello.exe.) - Run the executable:
./hello✅ Output:Hello, World!
Option 2: (Optional) Use Code Runner Extension
If you installed Code Runner, you can simply:
- Right-click inside your code and choose Run Code.
- Or press
Ctrl + Alt + N.
Output appears in the OUTPUT tab.
🧩 Step 4: (Optional) Setup a Build Task for One-Key Build & Run
If you want to press one shortcut to build and run:
- Press
Ctrl + Shift + B→ Choose C/C++: gcc build active file. - It creates a
.vscode/tasks.jsonfile. - Modify it to automatically run your program after build if you want.