Course contentsShow
← C
Lesson 17 of 1,2191. FoundationsFree lesson

The 'Hello World' code

The 'Hello World' code

What you'll learn: You will understand how a basic C program is structured and what each line does to produce a message on your screen.

Every programmer begins their journey with a simple ritual: writing a program that displays the phrase "Hello, World!" on the screen. It might seem small, but this code contains the essential "skeleton" required for every C program you will ever write.

The code

Copy or type this into your editor. Even if it looks like gibberish now, your computer sees it as a precise set of instructions.

#include <stdio.h>

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

Breaking it down

Think of a C program like a kitchen recipe. For the recipe to work, you need the right tools and a clear starting point.

  1. #include <stdio.h> : This is like grabbing a specific tool from the shed. The name stdio stands for "Standard Input Output." By including this, you are telling C that you want to use the standard tools for showing text on the screen. Without this line, the computer wouldn't know how to "talk" to you.
  2. int main() { ... }: This is the heart of your program. In C, the computer always looks for the word main first. It is the "Front Door" of your code. The curly braces { } act like a container, holding all the instructions that belong to that specific task.
  3. printf("Hello, World!");: This is the actual command to do work. printf is short for "print formatted." It takes whatever text you put inside the quotation marks and pushes it to the screen. Note the semicolon ; at the end—in C, this is like a period at the end of a sentence. It tells the computer, "This instruction is finished."
  4. return 0;: This is a status report. By returning zero, the program tells the operating system, "I finished my job successfully without any errors."

When you run this code, the computer enters the "Front Door" (main), grabs the "Printer" (stdio), shouts your message to the screen, and then closes the shop (return 0).

Key takeaway

Every C program starts at main(), uses #include to gain powers, and ends instructions with semicolons.