c-cpp-setup

VSCode Setup for C/C++

This guide will help you set up VSCode for your first C/C++ programming experience.

What You Need Before Starting

Note: Due to large file size, I cannot upload the VSCode installer to the repository. Please download it from the official website.

Step 1: Get VSCode

VSCode is a free text editor that makes programming easier.

  1. Go to https://code.visualstudio.com/download
  2. Click the big download button for your computer (Windows, Mac, or Linux)
  3. Wait for the download to finish

Step 2: Install VSCode

Windows

  1. Find the downloaded file (usually in Downloads folder)
  2. Double-click VSCodeUserSetup-x64-*.exe
  3. Click “Yes” when Windows asks permission
  4. Follow the setup steps:
    • Accept the agreement
    • Important: Check the box “Add to PATH” (this helps your computer find VSCode)
    • Click “Next” until “Install”
  5. Click “Finish” when done

Mac

  1. Find the downloaded file (usually in Downloads folder)
  2. Double-click the .zip file to extract it
  3. Drag the “Visual Studio Code” app to your Applications folder
  4. You can now open VSCode from Applications or Spotlight search

Linux (Ubuntu/Debian)

  1. Open Terminal (Ctrl+Alt+T)
  2. Go to your Downloads folder: cd Downloads
  3. Install VSCode: sudo dpkg -i code_*.deb
  4. If you see errors, run: sudo apt-get install -f

Linux (Fedora)

  1. Open Terminal (Ctrl+Alt+T)
  2. Go to your Downloads folder: cd Downloads
  3. Install VSCode: sudo rpm -i code_*.x86_64.rpm
  4. If you see errors, run: sudo dnf install -f

Step 3: Add Essential Extensions

VSCode needs extensions to understand C/C++ code and make programming easier. We’ll install two important ones:

Install C/C++ Extension (Required)

  1. Open VSCode (you should see a dark or light window)
  2. Look for the Extensions icon on the left side (looks like 4 squares) and click it
  3. In the search box at the top, type: C/C++
  4. Find “C/C++” by Microsoft (it should be the first result)
  5. Click the blue “Install” button
  6. Wait for it to install (you’ll see a progress bar)
  1. In the same Extensions panel, search for: Code Runner
  2. Find “Code Runner” by Jun Han (usually the first result)
  3. Click the blue “Install” button
  4. Wait for it to install

Why Code Runner? It makes running your programs much easier - just one click instead of typing commands!

Step 4: Create Your First Project

Let’s make a folder for your C/C++ programs.

  1. Create a new folder on your computer called “MyCPrograms” (you can put it on Desktop or Documents)
  2. In VSCode, click “File” → “Open Folder”
  3. Find and select your “MyCPrograms” folder
  4. Click “Select Folder” (Windows) or “Open” (Mac/Linux)

Step 5: Write Your First Program

  1. In VSCode, click “File” → “New File”
  2. Save it as hello.c (click “File” → “Save As”, type the name with .c at the end)
  3. Type this code exactly:
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}
  1. Save the file (Ctrl+S on Windows/Linux, Cmd+S on Mac)

Step 6: Run Your Program (Two Easy Ways!)

You have two great options to run your C programs. Try both and see which you prefer!

Method 1: Code Runner Extension (Beginner-Friendly)

This is the easiest way for beginners!

  1. Make sure your hello.c file is open and saved
  2. Option A: Click the “Run Code” button (▶️ triangle) in the top-right corner
  3. Option B: Right-click anywhere in your code and select “Run Code”
  4. Option C: Press Ctrl+Alt+N (Windows/Linux) or Cmd+Alt+N (Mac)

Your program will automatically compile and run! You’ll see the output in a panel at the bottom.

Advantages of Code Runner:

Method 2: Using Terminal (Great for Learning)

This method teaches you what’s happening behind the scenes.

  1. In VSCode, click “Terminal” → “New Terminal” (a command line appears at the bottom)
  2. Type these commands one by one (press Enter after each):

Windows:

gcc hello.c -o hello
hello.exe

Mac/Linux:

gcc hello.c -o hello
./hello
  1. You should see “Hello, World!” printed in the terminal

Advantages of Terminal:

Expected Results

No matter which method you choose, you should see:

Hello, World!

Congratulations! You just ran your first C program!

Configuring Code Runner (Optional but Helpful)

You can customize Code Runner to work exactly how you want:

  1. Go to “File” → “Preferences” → “Settings” (or press Ctrl+,)
  2. Search for “code runner”
  3. Useful settings to consider:
    • “Run In Terminal”: Check this box to run programs in the terminal instead of output panel
    • “Clear Previous Output”: Check this to clear old output before running new code
    • “Save File Before Run”: Check this to automatically save before running

What Each File Does

When you create more programs, you’ll see these file types:

Basic VSCode Tips for Beginners

Useful Shortcuts:

VSCode Features That Help:

Common Problems and Solutions

Problem: “gcc is not recognized” or “command not found”

Problem: Code Runner shows errors

Problem: Can’t find my files

Problem: Code doesn’t run

Problem: VSCode looks different

Problem: Code Runner output disappears quickly

Which Method Should You Use?

For Complete Beginners: Start with Code Runner - it’s simpler and lets you focus on learning C programming rather than compilation details.

As You Progress: Learn the terminal method too - it gives you more control and understanding of what’s happening.

Best Approach: Use Code Runner for quick testing and learning, terminal method when you need more control or are preparing for advanced topics.

Next Steps

Once you’re comfortable with this setup:

  1. Try writing more simple programs
  2. Experiment with both running methods
  3. Learn about variables, loops, and functions
  4. Practice compiling and running programs regularly
  5. Follow the Git Setup Guide to learn about version control

Windows only:

Quick Reference Card

To run your C programs:

Method Steps
Code Runner Save file → Click ▶️ button (or Ctrl+Alt+N)
Terminal (Windows) gcc filename.c -o filenamefilename.exe
Terminal (Mac/Linux) gcc filename.c -o filename./filename

Remember: Programming takes practice! Don’t worry if it seems confusing at first. Everyone starts here.

Your first C/C++ programming environment is ready!


Back to: Home Next: Git Setup