$ overview
overview/0x00·Foundations

Getting Started

What C is, how a program becomes an executable, and your first build.

C is a small language that sits close to the hardware. It has no garbage collector, no built-in string type, and no safety net for most mistakes — the compiler trusts you to know what you're doing. That sounds intimidating, but it's also why C is worth learning: once you understand it, most other languages start to feel like C with extra decoration.

Every C program starts life as plain text and goes through a pipeline before it can run:

From source code to a running program

  • Preprocessing — lines starting with # are expanded (covered in 0x0E).
  • Compiling — your C code is translated into assembly, then into machine code for your CPU.
  • Linking — your compiled code is joined with library code (like the functions behind printf) into a single executable file.

A compiler does all three steps for you. The most common ones are gcc and clang. If you don't have one installed, search for "install gcc" plus your operating system.

Your first program

Every C program needs a function called main — it's where execution begins. Save this as hello.c:

hello.c
1#include <stdio.h>
2 
3int main(void) {
4 printf("Hello, world!\n");
5 return 0;
6}

Then compile and run it from a terminal:

terminal
1gcc hello.c -o hello
2./hello

Reading the program line by line

  • #include <stdio.h> pulls in declarations for the standard input/output functions, including printf.
  • int main(void) declares a function named main that takes no arguments and returns an int.
  • printf(...) writes text to the terminal. \n is an escape sequence for a newline.
  • return 0; hands control back to the operating system. By convention, 0 means "the program succeeded."
note: Why int main(void) and not just main()
Older C code sometimes omits void or the return type. Modern C requires an explicit return type, and void explicitly says "this function takes no arguments" rather than leaving it unspecified.

Statements and semicolons

C doesn't care about line breaks or indentation the way Python does. Every statement ends with a semicolon, and whitespace is only there for humans. This means both programs below behave identically — but only one of them is worth writing:

equivalent.c
1int main(void) { printf("hi\n"); return 0; }

Consistent formatting matters purely for readability. Pick a style — this course indents with four spaces — and stick with it.

warning: Every statement needs a semicolon
Forgetting a semicolon is the single most common beginner error. The compiler will point at the line after the mistake, which can be confusing the first few times it happens.