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
- A C/C++ compiler already installed (follow Windows/Linux/macOS guide first)
- At least 1GB of free space on your computer
- At least 1GB of RAM
- Internet connection
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.
- Go to https://code.visualstudio.com/download
- Click the big download button for your computer (Windows, Mac, or Linux)
- Wait for the download to finish
Step 2: Install VSCode
Windows
- Find the downloaded file (usually in Downloads folder)
- Double-click
VSCodeUserSetup-x64-*.exe
- Click “Yes” when Windows asks permission
- Follow the setup steps:
- Accept the agreement
- Important: Check the box “Add to PATH” (this helps your computer find VSCode)
- Click “Next” until “Install”
- Click “Finish” when done
Mac
- Find the downloaded file (usually in Downloads folder)
- Double-click the
.zip
file to extract it
- Drag the “Visual Studio Code” app to your Applications folder
- You can now open VSCode from Applications or Spotlight search
Linux (Ubuntu/Debian)
- Open Terminal (Ctrl+Alt+T)
- Go to your Downloads folder:
cd Downloads
- Install VSCode:
sudo dpkg -i code_*.deb
- If you see errors, run:
sudo apt-get install -f
Linux (Fedora)
- Open Terminal (Ctrl+Alt+T)
- Go to your Downloads folder:
cd Downloads
- Install VSCode:
sudo rpm -i code_*.x86_64.rpm
- 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)
- Open VSCode (you should see a dark or light window)
- Look for the Extensions icon on the left side (looks like 4 squares) and click it
- In the search box at the top, type:
C/C++
- Find “C/C++” by Microsoft (it should be the first result)
- Click the blue “Install” button
- Wait for it to install (you’ll see a progress bar)
Install Code Runner Extension (Highly Recommended)
- In the same Extensions panel, search for:
Code Runner
- Find “Code Runner” by Jun Han (usually the first result)
- Click the blue “Install” button
- 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.
- Create a new folder on your computer called “MyCPrograms” (you can put it on Desktop or Documents)
- In VSCode, click “File” → “Open Folder”
- Find and select your “MyCPrograms” folder
- Click “Select Folder” (Windows) or “Open” (Mac/Linux)
Step 5: Write Your First Program
- In VSCode, click “File” → “New File”
- Save it as
hello.c
(click “File” → “Save As”, type the name with .c
at the end)
- Type this code exactly:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
- 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!
- Make sure your
hello.c
file is open and saved
- Option A: Click the “Run Code” button (▶️ triangle) in the top-right corner
- Option B: Right-click anywhere in your code and select “Run Code”
- 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:
- One-click solution
- Automatically handles compilation
- Works the same on all operating systems
- Perfect for learning and quick testing
Method 2: Using Terminal (Great for Learning)
This method teaches you what’s happening behind the scenes.
- In VSCode, click “Terminal” → “New Terminal” (a command line appears at the bottom)
- 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
- You should see “Hello, World!” printed in the terminal
Advantages of Terminal:
- Teaches you the compilation process
- More control over compiler options
- Essential skill for advanced programming
- Works in any environment
Expected Results
No matter which method you choose, you should see:
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:
- Go to “File” → “Preferences” → “Settings” (or press
Ctrl+,
)
- Search for “code runner”
- 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:
.c
files = Your C source code (the programs you write)
.cpp
files = Your C++ source code (the programs you write)
.exe
files (Windows) or executable files (Mac/Linux) = The compiled program that runs
.h
files = Header files (you’ll learn about these later)
Basic VSCode Tips for Beginners
Useful Shortcuts:
Ctrl+S
(Windows/Linux) or Cmd+S
(Mac) = Save your file
Ctrl+Z
(Windows/Linux) or Cmd+Z
(Mac) = Undo
Ctrl+C
and Ctrl+V
= Copy and paste
Ctrl+Alt+N
(Windows/Linux) or Cmd+Alt+N
(Mac) = Run code with Code Runner
VSCode Features That Help:
- Auto-complete: Start typing and VSCode suggests what you might want
- Error highlighting: Red underlines show mistakes in your code
- Line numbers: Shows line numbers on the left (helpful when you get error messages)
- IntelliSense: Smart code completion and error detection
Common Problems and Solutions
Problem: “gcc is not recognized” or “command not found”
- Solution: Your compiler isn’t installed properly. Go back to the compiler installation guide for your system.
Problem: Code Runner shows errors
- Solution: Make sure the C/C++ extension is installed and your compiler is working in the terminal first.
Problem: Can’t find my files
- Solution: Make sure you opened the correct folder in VSCode using “File” → “Open Folder”
Problem: Code doesn’t run
- Solution: Make sure you saved the file with
.c
extension and typed the code exactly as shown
Problem: VSCode looks different
- Solution: That’s okay! VSCode can look different based on settings, but the basic functions are the same
Problem: Code Runner output disappears quickly
- Solution: Enable “Run In Terminal” in Code Runner settings, or add
getchar();
before return 0;
in your code
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:
- Try writing more simple programs
- Experiment with both running methods
- Learn about variables, loops, and functions
- Practice compiling and running programs regularly
- 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 filename → filename.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!