Week 1: Setting Up the C Development Environment
Setting Up Your C Development Environment
Welcome to C Programming! Before writing any code, you need a working toolchain: a compiler, an editor, and the right configuration.
What is C?
C is a general-purpose, compiled, systems-level language created by Dennis Ritchie at Bell Labs in 1972. It underpins operating systems (Linux, Windows), embedded systems, and countless performance-critical applications. Learning C builds a deep understanding of how programs interact with hardware.
Step 1: Install VS Code
- Go to https://code.visualstudio.com and download the installer for your OS.
- Run the installer and follow the prompts.
- Launch VS Code after installation.
Step 2: Install a C Compiler
Windows — MinGW:
- Download MinGW from SourceForge.
- Run the setup and select mingw-developer-toolkit and mingw32-base.
- Click "Apply Changes" and wait for installation.
macOS — GCC via Xcode Tools:
xcode-select --install
Follow the on-screen prompts. GCC will be installed as part of the command-line tools.
Step 3: Add the Compiler to PATH
Windows:
- Open Start → search "Environment Variables" → Edit System Environment Variables.
- Under System Variables, find Path and click Edit.
- Add a new entry:
C:\MinGW\bin - Click OK to save.
macOS: GCC is auto-added to PATH after the Xcode install.
Verify the install by opening a terminal and running:
gcc --version
You should see a version number — not an error.
Step 4: Configure VS Code
- Open the Extensions panel (Ctrl+Shift+X).
- Search for C/C++ and install the extension by Microsoft.
- Open Settings (Ctrl+,) → search for "Run In Terminal" → enable Code Runner: Run in Terminal.
The "Run in Terminal" setting is critical — without it, scanf() (user input) won't work properly.
Step 5: Write and Compile Your First Program
- Create a file named
hello.c. - Paste this code:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
- Open the integrated terminal (Ctrl+`).
- Compile:
gcc hello.c -o hello
- Run:
./hello
The Compilation Process
C is a compiled language. Your source code goes through these steps:
| Step | Tool | Input → Output |
|---|---|---|
| Preprocessing | cpp | .c → expanded source |
| Compilation | gcc | source → assembly |
| Assembling | as | assembly → object file |
| Linking | ld | object files → executable |
When you run gcc hello.c -o hello, all four steps happen automatically.
Common First-Time Errors
| Error | Cause | Fix |
|---|---|---|
gcc: command not found |
MinGW not in PATH | Re-check PATH setup |
scanf hangs |
Code Runner not set to terminal | Enable "Run in Terminal" |
undefined reference to main |
Missing main() function |
Add int main() { ... } |