Nearby lessons

7 of 124

C - Environment Setup

Before you can run a single line of C you need two things: a compiler and an editor. This lesson helps you pick both, then walks through the four stages every C program passes through — Write, Compile, Link, Run — and ends with your first real compile using GCC.

Setting Up Your C Environment

To write and run C programs you need two things: a compiler (which turns your code into a runnable program) and an editor (where you type the code). Popular choices:

Tool What it is Best for
GCC (MinGW on Windows) The compiler — free and the standard Compiling from the command line
Code::Blocks Editor + compiler bundled together Beginners, college labs
VS Code + C/C++ extension Modern editor with a terminal Real-world development
Online compilers Run C in the browser Quick practice with no setup
In simple words: the editor is where you write, the compiler is what runs your writing. Online compilers skip the setup entirely — perfect for trying the examples in this tutorial.

How a C Program Runs — Write, Compile, Link, Run

A C program does not run directly. It passes through four stages, and you only do the first one yourself:

  • Write — you type the program into a file called program.c.
  • Compile — the compiler (like GCC) checks for errors and converts your code into object code.
  • Link — the linker joins your object code with the ready-made library functions (like printf).
  • Run — the resulting .exe file executes and shows the output.

Following one file through all four stages:

program.c        (source code — you write this)
     |
  COMPILER  (gcc)
     |
program.o        (object code — machine code, not yet runnable)
     |
   LINKER  (adds library code for printf, scanf, ...)
     |
program.exe      (executable — this is what runs)
In simple words: your .c file is a recipe, the compiler translates it into the machine's language, the linker adds the ready-made ingredients, and only then do you get something you can actually run.

Compiling and Running with GCC

GCC does the compile and the link together, so two commands take you from source file to output:

Command What it does
gcc program.c -o program Compiles and links, producing program.exe. The -o flag names the output.
gcc program.c Same, but the output gets the default name a.exe (a.out on Linux).
program Runs the executable you just built.
gcc program.c -o program -Wall Compiles with all warnings on. Use this — warnings catch real bugs.

A full session in the terminal looks like this:

C:\> gcc program.c -o program
C:\> program
Hello World
Trainer's Note: Memory trick: W-C-L-R — Write, Compile, Link, Run. Or remember "We Compile Like Runners". You only type the Write step; the compiler and linker silently do the middle two for you.
Common Mistake: running gcc and expecting output. gcc program.c -o program prints nothing when it succeeds — silence means it worked. You still have to run program to see the output.

Try It Yourself — Your First Compile

Save this as program.c, then run the two commands from the table above. If you see the greeting, your setup is working and you are ready for the next lesson.

Example04
CCode Cell
1#include <stdio.h>
2 
3int main()
4{
5 printf("Hello World\n");
6 return 0;
7}
Output
Hello World
📝 Key Takeaways
  • You need a compiler (GCC) and an editor — Code::Blocks, VS Code, or any text editor.
  • A C program does not run directly: write .c → compile → link → run the .exe.
  • The compiler checks errors and produces object code; the linker adds library functions.
  • Memory trick: W-C-L-R — Write, Compile, Link, Run.
  • gcc program.c -o program compiles and links in one step; then run program.

🧠 Test Your Knowledge

5 Questions
Progress: 0 / 5