C is a compiled language. You write code in a .c file, a compiler turns it into a program the computer can run, and then you run that program. Windows does not come with a C compiler, so the first job is to install one.
This page shows two ways to do it on Windows 10 or 11, then walks you through compiling and running Hello World. The last part covers the errors beginners hit most often.
Compiler, IDE and editor: what you are installing
| Term | What it is | Example |
|---|---|---|
| Compiler | Turns C code into an .exe program |
GCC, Clang, Microsoft C/C++ |
| IDE | Editor plus buttons to build, run and debug | Code::Blocks, Dev-C++, Visual Studio |
| Code editor | Editor only. You run the compiler yourself | VS Code, Notepad++ |
| MinGW-w64 | A Windows version of GCC | Comes with Code::Blocks or MSYS2 |
Pick one option:
- Option A: Code::Blocks with MinGW. One installer gives you an editor and a compiler. Best for your first week and for college lab work.
- Option B: GCC from the command line. Install GCC through MSYS2 and use any editor. Best if you want to learn the commands that work on Linux too.
You can install both. They do not conflict.
Option A: install Code::Blocks with MinGW
- Go to codeblocks.org and open Downloads, then Binary release.
- Under Windows, pick the setup file whose name contains mingw-setup, for example
codeblocks-XX.XXmingw-setup.exe. The version number changes. The important part is mingw. The plain setup file has no compiler. - Run the installer. Accept the licence, keep the default components and the default folder, and click Install.
- Start Code::Blocks. On the first run it shows a Compilers auto-detection window. GNU GCC Compiler should say "Detected". Select it, click Set as default, then OK.
Run Hello World in Code::Blocks
- Choose File > New > Empty file.
- Type the program below.
- Choose File > Save file as, pick a practice folder such as
C:\c-practiceand save it ashello.c. The.cending matters. If you save it ashello.cpp, it is compiled as C++. - Press F9 (or Build > Build and run).
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
}
A console window opens with:
Hello, World!
Process returned 0 (0x0) execution time : 0.015 s
Press any key to continue.
The first line is your program's output. The rest is added by Code::Blocks. Process returned 0 is the return 0; from main, and the execution time will be different on your machine.
Option B: install GCC with MSYS2
MSYS2 is a free tool that installs an up-to-date MinGW-w64 GCC on Windows.
- Go to msys2.org, download the installer and run it. Keep the default folder
C:\msys64. - When it finishes, open MSYS2 UCRT64 from the Start menu. A terminal window opens.
- Type this command and press Enter. When it asks to proceed, type
Y.
pacman -S mingw-w64-ucrt-x86_64-gcc
- Add GCC to PATH so Command Prompt can find it. Search Windows for "environment variables", open Edit the system environment variables, click Environment Variables, select Path under your user, click Edit, click New and add:
C:\msys64\ucrt64\bin
- Click OK on every window. Close any open Command Prompt windows.
Check that GCC works
Open a new Command Prompt (Windows key, type cmd, Enter) and type:
gcc --version
You should see a first line starting with gcc and a version number, followed by copyright text. If you see "not recognized", go to the errors section below.
Compile and run Hello World from the command line
Save the same Hello World program as C:\c-practice\hello.c using any editor, such as VS Code or Notepad. Then:
cd C:\c-practice
gcc hello.c -o hello
hello.exe
Output:
Hello, World!
| Command | What it does |
|---|---|
cd C:\c-practice |
Moves into the folder that has your file |
gcc hello.c -o hello |
Compiles hello.c and creates hello.exe |
hello.exe |
Runs the program. Typing hello also works |
If you leave out -o hello, GCC names the program a.exe on Windows (a.out on Linux). Compile again every time you change the code. Running hello.exe without compiling runs the old version.
Pro tip: Compile with
gcc -Wall hello.c -o hello. The-Wallflag turns on extra warnings that catch many beginner bugs before you run the program.
Understand your first program
| Line | Meaning |
|---|---|
#include <stdio.h> |
Brings in the standard input/output header, which declares printf and scanf |
int main(void) |
Every C program starts running from main |
{ and } |
Start and end of the body of main |
printf("Hello, World!\n"); |
Prints the text. \n moves to a new line |
return 0; |
Ends main and reports success |
Now try a program that reads input. Save it as add.c, compile it and run it:
#include <stdio.h>
int main(void) {
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
printf("%d + %d = %d\n", a, b, a + b);
return 0;
}
Sample run:
Enter two numbers: 15 27
15 + 27 = 42
%d is the format for an int. The & before a and b gives scanf the address where it should store each number. The C programming step by step guide explains this and the other basics in order.
What happens when you compile
hello.c --(compiler: gcc)--> hello.exe --(run)--> output on screen
The compiler checks your whole file first. If there is any error, it does not create the .exe, and nothing runs. This is different from Python, which runs line by line. Compiler vs interpreter explains the difference with examples.
Common errors and fixes
| Error message (or symptom) | Cause | Fix |
|---|---|---|
'gcc' is not recognized as an internal or external command |
The GCC bin folder is not on PATH |
Add C:\msys64\ucrt64\bin to PATH and open a new Command Prompt |
gcc: error: hello.c: No such file or directory |
You are in a different folder from the file | cd into the folder, or check the file name with dir |
error: expected ';' before 'return' |
A missing semicolon on the line above return |
Add ; at the end of the previous statement |
implicit declaration of function 'printf' |
#include <stdio.h> is missing |
Add the include line at the top. Newer GCC versions treat this as an error |
undefined reference to 'WinMain' |
No main function, often because the file was not saved or main is misspelled |
Save the file and check it says int main |
cannot open output file hello.exe: Permission denied |
The old hello.exe is still running |
Close the program's window, then compile again |
| Code::Blocks says "can't find compiler executable" | You installed the setup file without MinGW | Reinstall with the mingw-setup file, or point Code::Blocks to an installed GCC under Settings > Compiler > Toolchain executables |
| Console window closes immediately | You ran the .exe by double-clicking it |
Run it from Command Prompt, or use Code::Blocks, which keeps the window open |
Common mistake: Reading only the last error. A single missing semicolon or brace can produce several errors. Fix the first error GCC reports, compile again, and repeat.
Using VS Code for C
VS Code is a free editor, not a compiler. If you like it:
- Install GCC with Option B first.
- Install VS Code and the C/C++ extension from Microsoft.
- Open your practice folder, open
hello.c, and run it from VS Code's terminal with the samegcccommands shown above.
What to learn next
Once Hello World runs, move through the basics in order:
- Data types in C:
int,float,charand format specifiers. - Operators in C: arithmetic, relational, logical and increment.
- Decisions and loops, covered in C programming step by step.
- Arrays in C and strings in C.
Practise with short programs every day. The C programs for beginners with output page gives you a list to work through.
Frequently Asked Questions
Which C compiler is best for beginners on Windows?
What is the difference between Code::Blocks and GCC?
Why do I get gcc is not recognized?
Can I practise C without installing anything?
What does return 0 mean in main?
Want to Build Your Career in Java Full Stack with AI?
Join CodeBegun and train with working industry engineers — Explore the Java Full Stack program

