What you'll learn
C++ combines direct control over native resources with high-level abstractions that can be both expressive and efficient. In this lesson, you'll establish the modern mental model, install a C++20 toolchain, and compile your first native program.
By the end, you'll be able to:
- Explain what Modern C++ is and how it relates to—but differs from—C
- Describe preprocessing, compilation, linking, and execution
- Compile a warning-clean C++20 program with GCC or Clang
- Read the essential structure of a small C++ source file
How to use this course
What is Modern C++?
C++ is a general-purpose compiled language designed for software where performance, predictable resource use, portability, and rich abstraction all matter. It supports procedural, object-oriented, generic, functional, and low-level programming styles.
C++ grew from C and retains substantial compatibility, but it is its own language. Modern C++ code normally favors std::string, containers, algorithms, value types, and scope-bound resource owners over raw arrays and manual allocation.
Key idea
Modern C++ principles
| Principle | Meaning |
|---|---|
| Strong types | Make invalid operations difficult and intent visible |
| Value semantics | Objects behave like independent values when that matches the domain |
| RAII | Tie every resource lifetime to an object's lifetime |
| Zero-cost abstractions | Useful abstractions should not impose unnecessary runtime cost |
| Standard library first | Reuse specified containers, algorithms, strings, and utilities |
| Defined behavior | Avoid code whose meaning the language does not guarantee |
This course uses C++20 as its baseline. Later lessons identify selected C++23 facilities. Selecting a standard matters because the compiler should reject accidental reliance on unavailable language or library features.
Where C++ is used
C++ is strongest when an application needs control over latency, memory, hardware, or a large cross-platform native codebase while still benefiting from reusable abstractions.
Games & graphics
Engines · rendering · simulation
Systems software
Browsers · databases · compilers
Embedded & robotics
Devices · vehicles · real-time control
Creative tools
Audio · video · 3D applications
Finance & science
Low-latency · modeling · research
Cross-platform apps
Desktop · mobile · shared native cores
Note
How source becomes a program
A .cpp file is human-readable source. A toolchain translates it into machine instructions and combines it with the standard library and your other compiled files.
- The preprocessor handles directives such as
#include. - The compiler checks types and translates one translation unit.
- The assembler emits an object file containing native code.
- The linker resolves names across object files and libraries.
- The operating system loads and executes the resulting program.
Tip
Compiler & editor setup
Install a current GCC, Clang, or Microsoft Visual C++ toolchain. On Windows, Visual Studio, LLVM, MSYS2, or WSL are common choices. macOS provides Clang through Xcode Command Line Tools; Linux distributions provide GCC and Clang through their package managers.
g++ --version
clang++ --version
# In a Visual Studio Developer Command Prompt:
clUse an editor with C++ diagnostics and navigation—VS Code, Visual Studio, CLion, or another capable editor—but learn the terminal command too. It makes the real inputs to the compiler visible.
Your first program: Hello, World!
Create main.cpp and enter the following program:
#include <iostream>
int main() {
std::cout << "Hello, World!\n";
return 0;
}# GCC
g++ -std=c++20 -Wall -Wextra -Wpedantic main.cpp -o hello
./hello
# Clang uses the same core options
clang++ -std=c++20 -Wall -Wextra -Wpedantic main.cpp -o helloKeep strict warnings enabled
-std=c++20 selects the course baseline. -Wall -Wextra -Wpedanticrequests useful diagnostics. Warning names differ in MSVC, but the principle is the same.Anatomy of a C++ program
#include <iostream>makes standard stream declarations available.int main()defines the program's entry point.std::coutis the standard character-output stream.<<inserts a value into an output stream.\nwrites a newline without forcing an unnecessary flush.return 0;reports successful completion to the environment.
C++ is case-sensitive
main, Main, and MAIN are different names. Thestd:: prefix states that cout belongs to the standard namespace. Avoid a global using namespace std;; explicit qualification prevents collisions.Development workflow
- Edit one small, understandable change
- Compile with the selected standard and strict warnings
- Fix the first diagnostic before interpreting later cascaded errors
- Run normal, boundary, and invalid-input cases
- Save a working checkpoint in version control
A diagnostic normally includes a file, line, column, severity, and explanation. Read the exact source location and nearby context; one missing quote, brace, or semicolon can cause several later messages.
Comments
C++ supports line and block comments. Prefer clear names and small functions; use comments to preserve intent, constraints, units, ownership, or a non-obvious design decision.
#include <iostream>
int main() {
// Explain intent or a constraint—not obvious punctuation.
std::cout << "C++ rewards clear ownership.\n";
/* Block comments can span several lines,
but they do not nest. */
return 0;
}Watch out
Recap & quick check
Key takeaways
- Modern C++ combines native control with strong types, value semantics, RAII, and standard-library abstractions.
- The build pipeline preprocesses, compiles, assembles, and links translation units.
- C++20 is this course's explicit baseline; later features are labeled when introduced.
- std::cout writes standard output, and main returns a process status.
- Strict diagnostics and short edit-build-run cycles are everyday engineering tools.
Quick check
1. Which stage resolves names across object files and libraries?
2. What does std:: identify in std::cout?
3. Why select -std=c++20 explicitly?
4. Which principle ties resource cleanup to object lifetime?
Your Modern C++ toolchain is ready. Next: Module 2 — Variables, Fundamental Types & Operators, where programs begin representing and transforming real values.