Setup Environment (GCC, Dev-C++)
What You Need to Write C Programs
To write and run C programs, you need two things:
- A Text Editor or IDE — Where you write your C code (source code)
- A C Compiler — Converts your C code into machine language (executable)
The most popular C compiler is GCC (GNU Compiler Collection) — it's free, open-source, and available on all platforms.
| Tool | Type | Platform | Recommended For |
|---|---|---|---|
| Dev-C++ | IDE | Windows | Absolute beginners, school/college students |
| Code::Blocks | IDE | Windows, Linux, Mac | Beginners to intermediate |
| VS Code + GCC | Editor + Compiler | All platforms | Intermediate to advanced, professionals |
| gcc (terminal) | Compiler | Linux/Mac | Advanced, B.Tech students |
| OnlineGDB | Online IDE | Browser | Quick testing, no installation needed |
Go to https://www.onlinegdb.com/online_c_compiler — select C language and run code directly in your browser. Perfect for practicing while you learn.
Setup on Windows (Dev-C++)
Method 1: Dev-C++ (Easiest for Beginners)
Dev-C++ is a free IDE that includes the MinGW GCC compiler. One installer, ready to go.
- Go to:
https://sourceforge.net/projects/orwelldevcpp/ - Click Download and run the installer
- Accept all defaults during installation
- Open Dev-C++ → File → New → Source File
- Write your C code → Save as
hello.c - Press F9 or click Execute → Compile & Run
Method 2: Code::Blocks (Recommended)
- Go to:
http://www.codeblocks.org/downloads/binaries/ - Download:
codeblocks-XX.XXmingw-setup.exe(the one with mingw in name — this includes the compiler) - Run installer → select Full installation
- Open Code::Blocks → File → New → Empty File → Save as
hello.c - Write code → Press F9 to Build and Run
Always download the Code::Blocks version that includes mingw in the filename. Without mingw, you get the IDE but no compiler!
Setup on Linux (Terminal + GCC)
GCC is usually pre-installed on Linux. Check with:
gcc --version
If not installed, install it:
sudo apt update sudo apt install gcc
Write a C file, then compile and run:
nano hello.c # Write your C code gcc hello.c -o hello # Compile: creates 'hello' executable ./hello # Run the program
VS Code Setup (Best for Long-Term Use)
Step 1: Install VS Code
Download from https://code.visualstudio.com/ — free for all platforms.
Step 2: Install C/C++ Extension
- Open VS Code → click Extensions icon (left sidebar)
- Search: C/C++
- Install the extension by Microsoft
Step 3: Install GCC (Windows)
- Download MinGW-w64 from:
https://winlibs.com/ - Extract and add the
binfolder to your system PATH - Verify: open Command Prompt → type
gcc --version
Step 4: Compile via Terminal in VS Code
gcc hello.c -o hello -Wall # -Wall shows all warnings ./hello # Linux/Mac hello.exe # Windows
Your First Compilation – Step by Step
Let's write, save, compile and run your first C program:
#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }
The compilation process has 4 stages:
- Preprocessing — handles
#includeand#define - Compilation — converts C to assembly code
- Assembly — converts assembly to machine code (object file)
- Linking — links libraries and creates final executable
All 4 steps happen automatically when you run gcc hello.c -o hello.
Summary
- You need a compiler (GCC) and an editor/IDE to write C
- Beginners: use Dev-C++ or Code::Blocks on Windows
- Online practice: use OnlineGDB.com (no installation)
- Professional setup: VS Code + GCC
- Linux users: GCC is usually pre-installed or
sudo apt install gcc - Compile command:
gcc filename.c -o outputname
Frequently Asked Questions
How do I set up C on Windows?
.c file and compile it from the terminal or the IDE's build button.What compiler should a beginner use for C?
Do I need to install anything to write C programs?
How do I compile and run a C program from the terminal?
hello.c, then run gcc hello.c -o hello to compile it into a program called hello, and run it with ./hello on Linux or macOS, or hello.exe on Windows.