🎈 Kids Mode
XP: 0
🔴 C programs run with direct system access

Learn C Programming In Depth

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

  1. Go to https://code.visualstudio.com and download the installer for your OS.
  2. Run the installer and follow the prompts.
  3. Launch VS Code after installation.

Step 2: Install a C Compiler

Windows — MinGW:

  1. Download MinGW from SourceForge.
  2. Run the setup and select mingw-developer-toolkit and mingw32-base.
  3. 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:

  1. Open Start → search "Environment Variables" → Edit System Environment Variables.
  2. Under System Variables, find Path and click Edit.
  3. Add a new entry: C:\MinGW\bin
  4. 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

  1. Open the Extensions panel (Ctrl+Shift+X).
  2. Search for C/C++ and install the extension by Microsoft.
  3. 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

  1. Create a file named hello.c.
  2. Paste this code:
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}
  1. Open the integrated terminal (Ctrl+`).
  2. Compile:
gcc hello.c -o hello
  1. 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() { ... }