Getting Started with C

October 1, 2026 • 5 min read

Getting Started with C
Table of contents

Part of the series:C Explained

C is one of the oldest programming languages still in daily use, and it has never dropped out of the top of the language rankings. It was created in the early 1970s by Dennis Ritchie1 to write the Unix operating system, and it remains the language used to write operating systems, embedded devices, compilers, and the core of almost every other language. If you want to know what a computer really does when your code runs, C is the shortest path there: the language is small, and almost everything it does maps directly to what the hardware can do.

This post sets you up: what you need installed, your first program, and the path your source code takes from your editor to a running executable.

What you need

C has no official IDE, no package manager, and no runtime you install. To write C you need exactly three things:

  1. A compiler. The compiler2 translates your C source code into machine code the CPU can run. The two most common are gcc (GNU Compiler Collection) and clang (part of LLVM). Both are free and work on Linux, macOS, and Windows. On macOS you often get clang for free with the Command Line Tools; on Linux install gcc with your package manager; on Windows gcc comes inside MinGW, MSYS2, or WSL.
  2. A text editor. Any editor works because a .c file is just text. VS Code, Neovim, Vim, or a plain notepad all work. There is no special project format; you just type and save.
  3. A terminal. You will type a single command to build your program and another to run it.

That is everything. Check that your compiler exists by asking it its version:

gcc --version
# or
clang --version

If the terminal prints a version, you are ready.

Your first program

Create a file called hello.c and write this into it:

#include <stdio.h>

int main(void) {
    printf("Hello, world!\n");
    return 0;
}

That is a complete C program. It has three parts, and you will see the same skeleton in every C program you write:

  • #include <stdio.h> brings in the declaration of printf, the function used to print text. stdio.h is the standard header for standard input/output.
  • int main(void) defines the main function, the entry point. Every C program starts here. When you run the program, the operating system calls main.
  • printf("Hello, world!\n"); prints the text. \n is an escape sequence meaning “new line”, so the cursor moves to the next line after printing. The line ends with ;, because every statement in C ends with a semicolon.
  • return 0; tells the operating system the program finished successfully. A non-zero value signals an error.

The order inside main is the order of execution: print the line, then return 0.

Build and run

Open a terminal in the folder that contains hello.c and run:

gcc hello.c -o hello

Breaking that down: gcc is the compiler, hello.c is the input file, and -o hello says “put the result in a file named hello”. If the code is correct, this produces no output, just a new executable file. Now run it:

./hello

The ./ says “run the file in this directory”. You should see:

Hello, world!

That is the whole workflow: edit a .c file, compile it with gcc, run the executable. Every example in this series follows the same pattern.

What the compiler actually does

gcc hello.c looks like one step, but under the surface four steps happen in order3:

hello.c (source)
   ↓ 1. preprocessor: handles #include and #define
   ↓ 2. compiler: C → assembly
   ↓ 3. assembler: assembly → machine code (object file)
   ↓ 4. linker: object files + libraries → hello (executable)
  1. Preprocessing. Lines starting with # are handled first. #include <stdio.h> literally copies the contents of stdio.h into your file, so the compiler knows what printf looks like.
  2. Compiling. The C code is translated into assembly, the human-readable form of the CPU’s instructions.
  3. Assembling. The assembly is translated into machine code and saved as an object file. In the step above the object file is temporary and deleted, but you can keep it with the -c flag (gcc -c hello.c).
  4. Linking. Your object file is combined with pre-compiled libraries (like the code that actually knows how to talk to your terminal) into a single executable. This is the hello file you run.

You do not need to remember the details, only that source code passes through these stages and that each one can report its own error. Oh, and there is no fifth “runtime” step: the executable you build is a finished piece of machine code. The same compiler command produces it on any platform, which is why C is called portable: move the source to another machine, compile there, and it runs natively.

Compiling with warnings

Real C projects always compile with extra warnings enabled, because the compiler notices a lot of mistakes before your program runs:

gcc -Wall -Wextra hello.c -o hello

-Wall and -Wextra turn on a useful set of warnings. Treat every warning as a bug and fix it. The compiler is your first and fastest test suite.

The big picture

C is just three things to start: a compiler (gcc or clang), a text file ending in .c, and a build command (gcc file.c -o program). Your first program prints a line and returns zero. From here the series takes each piece of the language one at a time, starting with the syntax you will use in every single program you ever write.

The rest of the series uses the same commands everywhere, so this post is your reference whenever an example needs to be compiled.

Footnotes

  1. Dennis Ritchie - Wikipedia

  2. Compiler - Wikipedia

  3. Compiler - Wikipedia