How to Set Up VS Code for C and C++ Programming on Windows (Step-by-Step Guide)

How to Set Up VS Code for C and C++ Programming on Windows (Step-by-Step Guide)

Want to start coding in C or C++ using Visual Studio Code (VS Code)?
You’re in the right place. In this step-by-step guide, I’ll show you how to set up VS Code with MinGW (GCC Compiler) to write, compile, and run your C/C++ programs easily.

Perfect for:

  • Beginners

  • College students (BCA, B.Tech, Diploma)

  • Anyone who wants a lightweight coding setup

πŸš€ Step 1: Download and Install VS Code

  1. Download VS Code

  2. Install it on your system like any normal app.

βš™οΈ Step 2: Download and Install MinGW (GCC Compiler)

  1. Download MinGW

  2. During installation, make sure you select:

    • mingw32-gcc-g++

    • mingw32-gcc-gcc

  3. Install it to C:\MinGW

πŸ› οΈ Step 3: Setup Environment Variables

  1. Control Panel β†’ System β†’ Advanced System Settings β†’ Environment Variables

  2. Find Path β†’ Click Edit

  3. Add this path:

    C:\MinGW\bin

    🧩 Step 4: Install C/C++ Extension in VS Code

    1. Open VS Code

    2. Go to Extensions (Ctrl+Shift+X)

    3. Search and install C/C++ by Microsoft

πŸ’» Step 5: Write Your First C Program

    #include <stdio.h>

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

🏁 Step 6: Compile and Run

  1. Open Terminal (Ctrl+`)

  2. Compile the program:

    gcc filename.c -o output.exe
  1. Run the program:
    ./output.exe

⚑ Bonus Tip: tasks.json for Easier Compilation

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build and run",
                "type": "shell",
                "command": "gcc",
                "args": ["${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe", "&&", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
                "problemMatcher": ["$gcc"]
            }
        ]
    }

Now just press Ctrl+Shift+B to compile and run automatically.

🎯 Conclusion

Now you’re fully set to code, compile, and run C/C++ programs on Windows using VS Code. πŸ”₯

Need help? Drop a comment here or check my YouTube channel for the video version of this tutorial.


πŸ“š More Coming Soon:

  • C Programming Masterclass Playlist (2025 Edition) β†’ Subscribe on YouTube for updates

  • C Projects for Beginners

  • C to C++ Full Roadmap

    πŸ”” Connect with Me:

0
Subscribe to my newsletter

Read articles from Munish Kumar Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Munish Kumar Sharma
Munish Kumar Sharma

πŸ‘‹ Yo! I’m Munish β€” a full stack web dev + AI/ML learner building in public. πŸ’» On this channel: Beginner-friendly web development tutorials Dev vlogs + learning journey AI/ML experiments coming soon 🎯 Subscribe to grow with me and build cool stuff, one line of code at a time. #CodeWithMishu | Learn. Build. Dominate.