How to setup VS Code for c programming in Windows 10

Muhammad Hasan Zarif
2 min readDec 7, 2023

--

vs code

For those who don’t know about VS Code:

Visual Studio Code (VS Code) is a highly popular, free, and open-source source code editor developed by Microsoft for Windows, macOS, and Linux. Despite being lightweight, it functions as a powerful Integrated Development Environment (IDE) with features such as intelligent code editing, built-in Git integration, debugging tools, and terminal support. Noteworthy is its extensibility through a wide range of extensions, allowing users to customize and enhance their coding experience. With quick startup times and low resource consumption, VS Code has gained widespread adoption among developers.

Setting up Visual Studio Code (VS Code) for C programming on Windows 10 involves a few steps. Here’s a step-by-step guide:

Step 1: Install Visual Studio Code

1. Download Visual Studio Code from the official website: Visual Studio Code.
2. Run the installer and follow the on-screen instructions to complete the installation.

Step 2: Install MinGW for C Compiler

1. Download the MinGW installer from MinGW Installation Manager.
2. Run the installer and select the following packages for installation:
— mingw-developer-toolkit
— mingw32-base
— mingw32-gcc-g++
3. Click on “Installation” in the menu and select “Apply Changes.”

Step 3: Add MinGW to System Path

1. After installing MinGW, add its `bin` directory to the system PATH.
— Right-click on “This PC” or “Computer” on your desktop or in File Explorer.
— Select “Properties” > “Advanced system settings” > “Environment Variables.”
— Under “System variables,” find and select the “Path” variable, then click “Edit.”
— Click “New” and add the path to the MinGW `bin` directory (usually `C:\MinGW\bin`).
— Click “OK” to close the windows.

Step 4: Install the C/C++ Extension for VS Code

1. Open VS Code.
2. Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or use the shortcut `Ctrl+Shift+X`.
3. Search for “c/c++” in the Extensions view search box.
4. Install the one provided by Microsoft (ms-vscode.cpptools).

Step 5: Create a C Program

  1. Open VS Code.
  2. Create a new file with a .c extension, e.g., hello.c.
  3. Write a simple C program, for example:
#include <stdio.h>

int main() {
printf("Hello, World!\n");
return 0;
}

4. Save the file.

Step 6: Configure Tasks in VS Code

1. Press `Ctrl+Shift+B` to open the Command Palette.
2. Type and select “Tasks: Configure Default Build Task.”
3. Select “gcc.exe” from the list.

Step 7: Build and Run

1. Press `Ctrl+Shift+B` to build the C program.
2. Open the integrated terminal in VS Code (`Ctrl+` ` ` `) and navigate to the folder containing your C file.
3. Run the compiled program using `./<your_program_name>`.

Now, you should have a working setup for C programming in Visual Studio Code on Windows 10.

--

--