How to Run C Code

The computer doesn't read C directly

A computer only understands machine code: long lists of numbers. C is written in words that people can read. So before a C program can run, it must be translated.

The program that does this translation is called a compiler.

Think of it like this: A compiler is like a translator. You write a letter in English (your C code), the translator turns it into the language of the reader (machine code), and then the reader can follow it.

The three steps

  1. Write your code in a file that ends in .c, for example hello.c.
  2. Compile it. The compiler checks your code and turns it into a program.
  3. Run the program and see what it prints.

If you make a mistake, the compiler stops at step 2 and tells you which line is wrong. That is normal – every programmer sees these messages every day!

Option 1: Run C right here in your browser

Every module of this course ends with challenges. Each challenge has a code editor and a Run button, so you can write and run C straight away, without installing anything. This is the easiest way to start.

Tip: The browser editor uses a small, simple C runner. It runs all the everyday C in this course. A few advanced examples are marked "on your own computer with gcc": those need a full compiler.

Option 2: Run C on your own computer

Later, you may want a real compiler on your own computer. The most popular one is called gcc.

  • Linux: gcc is usually already installed. If not, run sudo apt install gcc.
  • macOS: run xcode-select --install in the Terminal.
  • Windows: install a free tool such as Code::Blocks or MSYS2, which include gcc.

Then compile and run your program in a terminal:

gcc hello.c -o hello
./hello
  • gcc hello.c compiles the file hello.c.
  • -o hello means "call the finished program hello".
  • ./hello runs it.

Remember: Write → Compile → Run. The compiler turns your C code into a program the computer can run.

HOME LABS COMMUNITY DASHBOARD