Skip to content

Getting Started with C++: Your First Program

Programming C++ Difficulty 1/5

Beginning of the lesson

Getting Started with C++

Write, compile, and run your very first program

Big Idea: A C++ program is plain text that you write. A special tool called a compiler turns that text into a program the computer can run. Today you will write the famous "Hello, World!" program and see it print a message on the screen.
By the end you will be able to:
  • explain the compile-then-run model,
  • recognise #include <iostream>, int main(), std::cout, ; and return 0;,
  • write and read a complete Hello World program and know its output.

1. The compile-then-run model

Unlike some languages that run your text directly, C++ works in two stages. First you write source code (a text file, usually ending in .cpp). Then a compiler reads that text and translates it into a program the computer understands. Only after that can you run the program to see its result.

1 2 3 4 Write code (.cpp) Compiler translates Program (executable) Run -> output
You write source code, the compiler translates it into an executable program, then you run it and the output appears.

If your code has a spelling or grammar mistake, the compiler will stop and show an error instead of a program. That is normal and helpful: fixing those messages is a big part of learning C++.

2. Your first program: Hello, World!

Here is the smallest useful C++ program. Type it exactly as shown:

#include <iostream>

int main() {
    std::cout << "Hello, World!";
    return 0;
}

Expected output:

Hello, World!

That is it! Four short lines print a message to the screen. Next we will look at what each line does.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers