C Workshop · Hello World
Lesson C

Hello World

The smallest useful C program prints a line, then exits.

What it is

Hello World is the smallest useful C program: it prints one line and exits. You use it to prove the compiler, the editor, and the terminal are all talking to each other.

Approach

  1. Include the standard I/O header so printf is declared.
  2. Put the work inside main — that is the start of every hosted C program.
  3. Call printf("Hello, Kodin!\n").
  4. Return 0.

Where this is used in the real world

Diagram

1

#include

bring in printf from stdio.h

Without this header, gcc may warn or error.
2

main()

the OS starts here

Every hosted C program needs an entry point.
3

printf

write characters to stdout

A newline ends the line so the next prompt is clean.
4

return 0

success status

Shells treat 0 as 'it worked'.

Run algorithm

Each step highlights the matching C line. Program output appears only when a line that prints actually runs.

Ready
C code
1#include <stdio.h>
2int main(void) {
3  printf("Hello, Kodin!\n");
4  return 0;
5}
What this line does
Press Run algorithm. The highlight will move through the C code.
Program output
(no output yet)

Check your understanding

Five questions. Pick one answer each, then Check answers. The correct choice turns green.

1. Why include stdio.h here?

Headers declare functions you call.

2. What does the n after the backslash in the format string do?

It is the newline escape.

3. If you omit the newline, what is a likely annoyance?

The shell prompt may sit on the same line.

4. How many times does this program call printf?

One call, then return.

5. Is Hello World interpreted or compiled in C?

Compile, then run.