Elemental SystemsSilicon · Boards · Software

Set Up Your Language · 9 of 14

Setting Up C

C is the classic language that most of computing is built on: Windows, Linux and Mac are largely written in it, as is the software inside washing machines, cars and phones' chips. It is small and very fast, and teaches you how computers really work. Like C++, it is compiled into a .exe. We install the free GCC compiler through MSYS2. (If you already set up C++ from this site, you already have it: skip to the check.)

Set-up: Medium (more steps)Official source: msys2.orgFile ending: .c

New to all this? Read Before you start on the main page first: it shows how to open Terminal, make a folder for your code, and see file name endings. It takes five minutes and prevents most problems.

1 What to download, and from where

Download only from msys2.org, the official MSYS2 website (GCC itself is a GNU project, gcc.gnu.org). Other download sites can bundle unwanted software.

  1. Go to msys2.org, the official MSYS2 site. Under Installation, click the installer link (a file named like msys2-x86_64-20xxxxxx.exe).

2 Install it on Windows

  1. Open the downloaded file. Click Next on each screen and keep the suggested folder C:\msys64. Click Finish at the end.
  2. A black window titled UCRT64 (or MSYS2 UCRT64) opens. This is MSYS2's own terminal. If it does not open, press the Windows key, type MSYS2 UCRT64 and open it.
  3. In that window, type this line and press Enter (copy it exactly):
    pacman -S --needed mingw-w64-ucrt-x86_64-gcc
    It lists what it will download and asks Proceed with installation? [Y/n]. Press Enter to say yes. It downloads for a minute or two.
  4. Add the compiler's folder C:\msys64\ucrt64\bin to your PATH, so Windows can find it from any Terminal (step-by-step instructions). Then close and reopen Terminal.

3 Check that it worked

Close every Terminal window you have open and open a new one. A Terminal that was already open does not know about programs installed after it started. Then type this and press Enter:

gcc --version

What you will see: A first line with Built by MSYS2 project and a version number. Run this in a normal Terminal to prove the PATH step worked.

gcc.exe (Rev8, Built by MSYS2 project) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.

If you see an error such as "is not recognized" instead, look at the common mistakes at the bottom of this page.

4 Write and save your first program

A program is just a text file. You can write it in Notepad, which comes with Windows. (Later you may like the free Visual Studio Code editor from code.visualstudio.com, which colours the code and helps spot mistakes.)

  1. Open Notepad (press the Windows key, type Notepad, press Enter).
  2. Type the program below, or click Copy and paste it in with Ctrl + V. Every symbol matters, so copy it exactly.
    #include <stdio.h>
    
    int main(void) {
        printf("Hello, World!\n");
        return 0;
    }
  3. In Notepad choose File → Save as. Go to your C:\code folder. Set Save as type to All files (*.*), type the file name hello.c exactly as shown, including the dot and the ending, and click Save.

#include <stdio.h> brings in the standard input/output tools. main is where the program starts. printf prints text, and \n means "new line". return 0 tells Windows the program finished without problems.

Do not use Word. Word saves extra formatting and changes straight quotes " into curly ones “ ”, which no programming language accepts.

5 Run it and see the result

Two steps: compile the program into an .exe, then run it.

Open File Explorer, go into your C:\code folder, right-click an empty part of the window and choose Open in Terminal. (More ways to open Terminal.) If Terminal was already open from the check above and is in another folder, type cd C:\code and press Enter.

Type these lines one at a time, pressing Enter after each:

gcc hello.c -o hello.exe
.\hello.exe

What you will see: the words below on a new line. That is your program running.

Hello, World!

Each time you change hello.c, compile again before running, or you will still run the old version.

Congratulations: you have written and run a C program.

6 Common beginner mistakes and how to fix them

Error messages look alarming but are usually precise: read the first line, and look for a line number. If you are stuck, copy the whole error message and paste it into an AI assistant along with your code, and ask what it means.

The program built, but there is no hello.exe (there is an a.exe instead)

Why: you left out -o hello.exe, so GCC used its default name.
Fix: run .\a.exe, or build again with -o hello.exe.

error: expected ';' before 'return'

Why: a semicolon is missing at the end of the line before. C reports the problem where it noticed it, often the line after the real mistake.
Fix: add ; at the end of the printf line.

warning: implicit declaration of function 'printf'

Why: the #include <stdio.h> line is missing or misspelt, so C does not know what printf is.
Fix: put #include <stdio.h> as the first line, exactly as shown.

'gcc' is not recognized as an internal or external command

Why: Windows cannot find the program. Either the Terminal was open before you installed it, or the program's folder is not on the PATH (the list of folders Windows searches for commands).
Fix: Close every Terminal window you have open and open a new one. A Terminal that was already open does not know about programs installed after it started. If it still fails, restart the computer, then check the folder is on the PATH (how to check and add it). The folder to add is C:\msys64\ucrt64\bin.