Skip to content
Lesson 1 of 13

Step 1 of 5 · Reading · ~3 min

Learn

Getting Started

Hello, World

C is fifty years old, runs everything beneath everything (your OS kernel, your language runtimes, your microwave), and has exactly one setting: manual. Learning C is learning what computers actually do — which is why this course exists, and why the languages you already know will make more sense after it.

#include <stdio.h>

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

Line by line, because each one carries real machinery:

  • #include <stdio.h> — a preprocessor directive: before compilation proper, the text of the standard I/O header is pasted here, declaring printf so the compiler knows its shape. C has no automatic imports; you ask for every header you use.
  • int main(void) — the entry point. It returns an int to the operating system: 0 means success, non-zero means failure. Shell scripts and CI pipelines genuinely read this value (echo $?) — it's not ceremony.
  • printf("...\n") — print formatted text, and nothing is appended for you: no \n in your string, no newline in your output. That \n is two characters typed inside the quotes, a backslash then an n. Type /n by accident and you have not made a newline, you have made a division and a variable name — the compiler's complaint will point at the line but not at the slash.
  • return 0; — report success. (Modern C returns 0 implicitly from main if you omit it — write it anyway; explicit is the C way.)

The compile step is real

C doesn't run from source. You translate it to machine code first, and the translator is blunt about errors:

$ gcc -Wall -o hello hello.c
$ ./hello
Hello, World

-Wall turns on warnings, and you should treat it as mandatory. C's compiler, unlike Rust's, will happily compile many programs that are wrong — uninitialized variables, suspicious conversions, format-string mismatches. -Wall (and its friend -Wextra) upgrade the compiler from "translator" to "reviewer." A C programmer who ignores warnings is a C programmer with mysterious crashes; the platform's grader compiles your code for you, but read its compile output like it owes you money.

What C doesn't do for you

Setting expectations now saves confusion later. C has: no garbage collector (you free memory yourself — chapter 5), no bounds checking (read past an array and C hands you whatever bytes were there — chapter 2), no string type (strings are arrays with a convention — chapter 2), no exceptions (errors are return values you check). Every one of these is a deliberate trade for speed and control, every one is a way to shoot yourself in the foot, and — the real point of this course — every one teaches you what the "safe" languages are protecting you from and what that protection costs.

Your exercise

Print the exact text: one printf, the string, the explicit \n. The comparison is on the characters you print — Hello, C ! and hello, c! are both failures — and the one thing it forgives is whitespace at the very end, so a missing final newline still passes here. Write it anyway: a terminal, a log file and the next program in a pipeline all care, and the habit is one character long.

Then break something on purpose — remove the semicolon, misspell printf — and read the error. C's diagnostics are terser than Rust's, and building tolerance for them early is a genuine skill: the error's line number is usually right even when its message is cryptic, and the actual mistake is on that line or the one above it.

Up nextVariables and TypesGetting Started

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…