C++ Academy · Lesson

Hello World and Build Process

Write Hello World, understand preprocessing, compilation, assembly, and linking stages.

Lesson 2 of 413 steps

Hello World and Build Process is a free C++ Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the C++ Academy learning path, and your progress syncs across the web and the CoddyKit app. The C++ Academy course includes 4 lessons in total.

The Simplest C++ Program

Every C++ program starts with main(). The runtime calls main first and exits when it returns.

#include <iostream>

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

What #include Does

The #include directive is processed by the preprocessor before compilation. It textually pastes the contents of a header into the source file.

The std Namespace

Standard library names live in the std namespace. We prefix them with std:: like std::cout. Avoid using namespace std; in headers — it pollutes the global namespace.

Stream Insertion <<

The << operator inserts data into an output stream. Chain it to print multiple values in one expression.

std::cout << "Name: " << name << ", Age: " << age << "\n";

endl vs \n

Both end a line. std::endl also flushes the buffer — slower in tight loops. Prefer "\n" for general use.

The Build Process: Four Stages

Building a C++ program goes through four stages:

  • Preprocess — expand includes and macros
  • Compile — source to assembly
  • Assemble — assembly to object code
  • Link — combine objects into the final executable

Compiling Hello World

From a terminal, save the file as hello.cpp and run g++. The default output name is a.out; use -o to choose your own.

g++ -std=c++20 hello.cpp -o hello
./hello

Inspecting Each Stage

You can stop after any stage with a flag:

  • -E — preprocess only
  • -S — compile to assembly
  • -c — compile and assemble, do not link

Object Files and Linking

Each translation unit (a .cpp file) becomes an object file (.o or .obj). The linker combines object files and resolves external references to produce the executable.

Header Files and Their Role

Headers (.h or .hpp) declare functions and classes. Source files (.cpp) define them. Including a header brings declarations into a translation unit.

Common First Errors

If your program does not compile, check:

  • Missing semicolon at end of statement
  • Forgot to #include <iostream>
  • Mismatched { and }
  • Wrong capitalization — C++ is case sensitive

Quick Check

Which build stage combines object files into the final executable?

Recap

Every C++ program has a main() function. The compiler runs preprocess, compile, assemble, and link stages. Use std::cout with << to print, and prefer "\n" over std::endl.

Free to start

Learn C++ with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
51
Lessons
203

Frequently Asked Questions

Is the “Hello World and Build Process” lesson free?

Yes — any 3 lessons of the C++ Academy learning path, including “Hello World and Build Process”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The C++ Academy course includes 4 lessons in total.

What will I learn in “Hello World and Build Process”?

Write Hello World, understand preprocessing, compilation, assembly, and linking stages. You practise C++ Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start C++ Academy?

No prior experience is required. C++ Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

How long does the “Hello World and Build Process” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this C++ Academy lesson?

Yes. Every C++ Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Setting Up a C++ Compiler
  2. Hello World and Build Process
  3. Variables, Auto Type Inference and constexpr
  4. Basic Operators and Type Conversion
← Back to C++ Academy