This mini-course covers “classic” C arrays (T a[N]) and modern STL alternatives (std::array, std::vector, std::span), focusing on safe usage, passing to functions, and algorithms.
- A compiler with C++20 support (e.g.,
g++10+ orclang++12+). - A terminal and basic build knowledge.
One example (replace with the file you want):
g++ -std=c++20 -O2 -Wall -Wextra -pedantic -g 01_basic_c_array.cpp -o app
./appBuild all examples (one executable per file):
for f in *.cpp; do
g++ -std=c++20 -O2 -Wall -Wextra -pedantic -g "$f" -o "${f%.cpp}"
doneRun, for example:
./10_stl_algorithms- Setup and recommended flags
- Basic C array
- Initialization and
sizeof - Array-to-pointer decay (classic pitfall)
- Pointers and iteration
- Passing arrays to functions (4 ways)
std::array- 2D arrays and flatten (row-major)
- Dynamic:
new[]/delete[](educational) and RAII std::spanand views- STL algorithms on arrays
- Mini-project: ring buffer with
std::array - Pointer to array vs array of pointers