Getting Started with C++
Compile your first program, and meet the value semantics, references, and pointers that define C++.
C++ is a compiled, statically typed language that gives you control over memory and performance while still offering high-level abstractions. It is the standard choice for systems programming, game engines, high-frequency trading, and competitive programming — anywhere speed and predictability matter.
The single idea that separates C++ from most languages is how it treats names and memory. Step through the model below: watch which boxes change when you copy a value, alias it with a reference, or point at it.
Hello, world
#include <iostream>
int main() {
std::cout << "Hello, world!\n";
return 0;
}
Compile and run it with a modern compiler:
g++ -std=c++20 -O2 hello.cpp -o hello
./hello
The -std=c++20 flag selects the language standard and -O2 turns on
optimizations.
Values, references, and pointers
This is the idea that trips up newcomers, and it is the heart of C++:
- A value is a copy.
int b = a;givesbits own independent copy ofa. - A reference (
int& r = a;) is another name for an existing object. Changingrchangesa. - A pointer (
int* p = &a;) stores the address of an object. You follow it with*pand it can be reseated or null.
int a = 10;
int& r = a; // r is an alias for a
int* p = &a; // p holds the address of a
r = 20; // a is now 20
*p = 30; // a is now 30
Understanding when data is copied versus shared is what makes C++ fast — and what makes dangling references and leaks possible if you are careless. Later lessons cover RAII (tying resource lifetime to scope), smart pointers, templates, and the STL containers and algorithms.
Why C++ for this site
Many data-structure and algorithm problems are written in C++ because it maps closely to what the machine does, so the cost model in those lessons is concrete. Running C++ against test cases in the browser arrives with the problem judge in a later phase; for now these lessons focus on the language and its mental model.
Takeaways
- C++ is compiled and statically typed, trading some convenience for speed and control.
- Value semantics by default; references alias, pointers hold addresses.
- Knowing what gets copied versus shared is the foundation everything else builds on.