Hello World and Build Process
Write Hello World, understand preprocessing, compilation, assembly, and linking stages.
Hello World and Build Process is a free C++ Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C++ Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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
./helloInspecting 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.
Frequently asked questions
Is the “Hello World and Build Process” lesson free?
Yes — the full text of “Hello World and Build Process” is free to read here on the web, and the C++ Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C++ Academy course, upgrade to CoddyKit PRO.
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; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
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
- Setting Up a C++ Compiler
- Hello World and Build Process
- Variables, Auto Type Inference and constexpr
- Basic Operators and Type Conversion