CBasicsbeginner

Install a C Compiler and Run Your First Program

Set up GCC or Code::Blocks on Windows, compile and run your first C program, and fix the errors beginners hit most often.

Published
TL;DR – Quick Answer

The easiest way to get a C compiler on Windows is to install Code::Blocks using the installer that includes MinGW, then create hello.c and press F9 to build and run it. For the command line, install GCC through MSYS2 (MinGW-w64), add its bin folder to PATH, then run gcc hello.c -o hello followed by hello.exe.

On This Page

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

  1. Go to codeblocks.org and open Downloads, then Binary release.
  2. 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.
  3. Run the installer. Accept the licence, keep the default components and the default folder, and click Install.
  4. 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

  1. Choose File > New > Empty file.
  2. Type the program below.
  3. Choose File > Save file as, pick a practice folder such as C:\c-practice and save it as hello.c. The .c ending matters. If you save it as hello.cpp, it is compiled as C++.
  4. 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.

  1. Go to msys2.org, download the installer and run it. Keep the default folder C:\msys64.
  2. When it finishes, open MSYS2 UCRT64 from the Start menu. A terminal window opens.
  3. Type this command and press Enter. When it asks to proceed, type Y.
pacman -S mingw-w64-ucrt-x86_64-gcc
  1. 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
  1. 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 -Wall flag 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:

  1. Install GCC with Option B first.
  2. Install VS Code and the C/C++ extension from Microsoft.
  3. Open your practice folder, open hello.c, and run it from VS Code's terminal with the same gcc commands shown above.

What to learn next

Once Hello World runs, move through the basics in order:

  1. Data types in C: int, float, char and format specifiers.
  2. Operators in C: arithmetic, relational, logical and increment.
  3. Decisions and loops, covered in C programming step by step.
  4. 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?
GCC is free and used in most colleges and coding platforms. On Windows you get it through MinGW-w64, either inside Code::Blocks or through MSYS2. Visual Studio's compiler also works but is a much larger install.
What is the difference between Code::Blocks and GCC?
GCC is the compiler that turns C code into a program. Code::Blocks is an IDE, an editor with buttons for building and running. The Code::Blocks installer with mingw in its name includes a copy of GCC.
Why do I get gcc is not recognized?
Windows cannot find gcc.exe because its folder is not on PATH, or you opened Command Prompt before changing PATH. Add the compiler's bin folder to PATH and open a new Command Prompt window.
Can I practise C without installing anything?
Yes. Online C compilers let you type and run code in a browser. They are fine for quick practice, but install a compiler on your laptop for lab work and projects.
What does return 0 mean in main?
It tells the operating system that the program finished without an error. A non-zero value usually signals that something went wrong.

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

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 5 December 2026 LinkedIn
Chat with us