Skip to content

Hello, World!

Read · 1 of 5

A program is a list of instructions

The computer follows them one at a time, top to bottom. This is the smallest useful C program: it prints one line.

1#include <stdio.h>
2
3int main() {
4 printf("Hello, World!\n");
5 return 0;
6}
Read this lesson as text

The smallest C program, line by line.

A program is a list of instructions

The computer follows them one at a time, top to bottom. This is the smallest useful C program: it prints one line.

#include <stdio.h>

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

What happens when you run it

  1. Your code: hello.c: text you can read
  2. Compiler: gcc checks it and translates it
  3. Program: machine instructions
  4. Output: what you see printed

Watch it run

#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}
  1. Line 1: #include <stdio.h> brings in the standard input/output tools, like printf. Almost every C program starts with it.
  2. Line 3: Every C program starts running inside main(). The code between { and } is what runs.
  3. Line 4: printf prints the text inside the quotes. \n is a special pair of characters meaning "new line".
  4. Line 5: return 0 tells the operating system the program finished without problems.

Your turn to guess

#include <stdio.h>

int main() {
    printf("Hi\n");
    printf("there\n");
    return 0;
}

What does this print?

  • Hi there
  • Hi there
  • Hithere
Show the answer

Hi there Each \n ends the line, so "there" starts on a new one.

Exercise: Say hello

Print exactly: Hello, ICEM!