step-by-step to install and run C/C++ code on your computer using VS Code

🧰 What You Need to Install:

  1. βœ… A code editor (like VS Code)

  2. βœ… A C/C++ compiler (like MinGW or GCC)

  3. βœ… C/C++ extensions for your editor


πŸͺŸ Step-by-Step: Install C/C++ on Windows (VS Code + MinGW)

βœ… Step 1: Install VS Code

  1. Download from πŸ‘‰ https://code.visualstudio.com

  2. Install it with default settings (check β€œAdd to PATH”).


βœ… Step 2: Install MinGW Compiler

  1. Go to πŸ‘‰ https://www.mingw-w64.org or download directly from:
    πŸ‘‰ https://sourceforge.net/projects/mingw-w64/

  2. Run the installer:

    • Version: x86_64

    • Threads: posix

    • Exception: seh

    • Build revision: any is fine

    • Install to a folder like: C:\mingw-w64

  3. After install, add it to System PATH:

    • Go to Start > Environment Variables

    • Under System Variables, find Path β†’ Edit

    • Add: C:\mingw-w64\bin (your exact path may vary)

  4. To test if it works:

    • Open Command Prompt

    • Type:

      bash
      g++ --version
    • You should see a version number (like g++ (GCC) 13.x.x)


βœ… Step 3: Install C/C++ Extension in VS Code

  1. Open VS Code

  2. Press Ctrl+Shift+X to open Extensions

  3. Search for:
    πŸ‘‰ “C/C++” by Microsoft

  4. Click Install


βœ… Step 4: Write and Run C or C++ Code

  1. Create a new folder and open it in VS Code

  2. Create a new file like main.cpp or main.c

  3. Paste sample code:

Example for C:

c
#include <stdio.h>

int main() {
printf("Hello from C!\n");
return 0;
}

Example for C++:

cpp
#include <iostream>
using namespace std;

int main() {
cout << "Hello from C++!" << endl;
return 0;
}


βœ… Step 5: Compile and Run Your Code

  1. Open Terminal in VS Code (Ctrl + ~)

  2. Type:

    bash
    g++ main.cpp -o app
    ./app

    or (for C):

    bash
    gcc main.c -o app
    ./app

πŸŽ‰ You should see:

csharp
Hello from C++!

or

csharp
Hello from C!

🐧 For Linux Users

  1. Open Terminal

  2. Install compiler:

    bash
    sudo apt update
    sudo apt install build-essential
  3. Then compile:

    bash
    g++ main.cpp -o app
    ./app

🍎 For macOS Users

  1. Open Terminal

  2. Install Xcode tools:

    bash
    xcode-select --install
  3. Compile and run like on Linux.


🧠 Summary

Tool Purpose
VS Code Code writing/editor
MinGW Compiler for C/C++
g++/gcc Build and run code
C/C++ ext Syntax, IntelliSense

Leave a Comment