A comprehensive, hands-on C++ learning repository organized as a structured course. Each lesson is self-contained with practical examples you can compile and run independently. Progresses from beginner fundamentals to intermediate concepts using modern C++20+ standards.
This repository contains 9 comprehensive modules covering essential C++ programming concepts:
- 90+ practical examples across different difficulty levels
- Self-contained lessons - each
.cpp
file compiles independently - Modern C++ practices (C++20+ standards)
- Real-world applications and exercises
- Progressive difficulty from basics to advanced topics
# macOS (recommended)
xcode-select --install # Apple Clang compiler
brew install cmake llvm clang-format # Optional tools
# Verify installation
clang++ --version
# Create build directory
mkdir -p build
# Compile with modern C++ standards and warnings
clang++ -std=c++20 -Wall -Wextra -Wpedantic -g introduction/Test.cpp -o build/test
./build/test
# With sanitizers (debug mode)
clang++ -std=c++20 -g -O0 -fsanitize=address,undefined pointer/startPointer.cpp -o build/pointer_demo
./build/pointer_demo
Folder: introduction/
Test.cpp
- Hello World and basic I/OTest2.cpp
- Variables and data typesoperator.cpp
- Arithmetic, logical, and comparison operators
Key Concepts: Basic syntax, cout/cin, variables, operators, type system
Folder: condition/
if.cpp
- Basic if statementsif_else.cpp
- If-else branchingif_else_if.cpp
- Multi-branch conditionsswitch.cpp
- Switch-case statementsTernaryOperator.cpp
- Conditional operator (?:)nested_statement.cpp
- Nested conditional logic
Key Concepts: Decision making, branching logic, control flow
Folder: loop/
for_loop.cpp
- For loop fundamentalswhile_loop.cpp
- While loop patternsdo_while_loop.cpp
- Do-while loopsnested_loop.cpp
&nested_loop_2.cpp
- Nested iterationgoto_label.cpp
- Label and goto (educational)pow.cpp
&pow_2.cpp
- Mathematical calculationssum_data.cpp
- Data processing examplesworker.cpp
- Real-world loop applications
Key Concepts: Iteration, nested loops, loop control, algorithms
Folder: function/
return_none_param.cpp
- Functions without parametersreturn_has_param.cpp
- Functions with parametersnone_return_param.cpp
&none_return_has_param.cpp
- Void functionsfunction_PassByValue.cpp
&function_PassByValue1.cpp
- Pass by valuefunction_PassByReferent.cpp
- Pass by referenceoverloading.cpp
&overloading2.cpp
- Function overloadingrecursive_function.cpp
&recursive_function2.cpp
- Recursionpersion.cpp
&product.cpp
- Real-world examples
Key Concepts: Function design, parameter passing, recursion, overloading
Folder: array/
hello.cpp
- Basic array operationstest.cpp
- Array fundamentalsTwoArra.cpp
&arrayTwoDimension.cpp
- 2D arraysuserTwoDimension.cpp
- Interactive 2D array inputThreeDimansion.cpp
- 3D array operationspersion.cpp
&employee.cpp
- Object arraysproduct.cpp
&catogory.cpp
- Real-world data structures
Key Concepts: Array manipulation, multi-dimensional arrays, data organization
Folder: pointer/
startPointer.cpp
- Pointer fundamentalslevelPointer.cpp
- Multi-level pointerspointerArray.cpp
- Pointer-array relationshipmallocPointer.cpp
&mallocPointerTwo.cpp
- Dynamic allocationcallocOne.cpp
- Calloc memory allocationrealloc.cpp
- Memory reallocationfunctionPointer.cpp
&functionPointerRedom.cpp
- Function pointers
Key Concepts: Memory management, dynamic allocation, pointer arithmetic
Folder: structure/
helloStructure.cpp
- Basic struct definitionnestedStruct.cpp
- Nested structuresbookArray.cpp
&employeeArray.cpp
- Arrays of structuresobjectPointer.cpp
- Pointer to structuresobjectStructArray.cpp
- Complex data organizationtypedefStructure.cpp
- Type aliaseserrorStudent.cpp
- Error handling examples
Key Concepts: Data encapsulation, custom types, structured programming
Folder: template/
function_template.cpp
- Function templatesstruct_template.cpp
- Class templatestwo_template.cpp
- Multiple template parameters
Key Concepts: Generic programming, code reusability, template specialization
Folder: exception/
exception.cpp
- Try-catch blocks, throwing exceptions
Key Concepts: Error handling, exception safety, robust programming
# Development (with warnings)
-std=c++20 -Wall -Wextra -Wpedantic -Wconversion -Wshadow -g
# Debug (with sanitizers)
-std=c++20 -g -O0 -fsanitize=address,undefined -fno-omit-frame-pointer
# Release (optimized)
-std=c++20 -O2 -DNDEBUG
Create a unified build system:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(cpp_lessons LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Add compiler warnings
add_compile_options(-Wall -Wextra -Wpedantic)
# Example executable
add_executable(lesson_runner src/main.cpp)
- Start with
introduction/
- understand basic syntax - Master
condition/
- learn decision making - Practice
loop/
- understand iteration patterns
- Study
function/
- learn modular programming - Explore
array/
- understand data collections - Master
pointer/
- learn memory management
- Build with
structure/
- create custom types - Generalize with
template/
- write reusable code - Handle errors with
exception/
- robust programming
- Calculator (modules 1-3): Basic arithmetic with menu system
- Grade Manager (modules 4-5): Student grade calculations and arrays
- Simple Games (loops + conditions): Number guessing, tic-tac-toe
- Contact Manager (structures + arrays): Store and search contacts
- File Processor (pointers + functions): Read/write text files
- Data Analyzer (templates): Generic statistical functions
- Memory Pool (pointers + templates): Custom memory allocator
- Expression Parser (all concepts): Mathematical expression evaluator
- Mini Database (structures + templates + exceptions): Data storage system
# Compiler not found
xcode-select --install
# Permission denied
chmod +x ./build/program_name
# Memory errors
# Recompile with: -fsanitize=address,undefined -g
- Use
clang-format
for consistent formatting - Enable
clang-tidy
for static analysis - Follow modern C++ best practices (RAII, smart pointers)
- Module 1: Introduction & Fundamentals
- Module 2: Conditional Logic
- Module 3: Loops & Iteration
- Module 4: Functions & Modularity
- Module 5: Arrays & Data Collections
- Module 6: Pointers & Memory Management
- Module 7: Structures & Custom Types
- Module 8: Templates & Generic Programming
- Module 9: Exception Handling
Feel free to:
- Add new examples to existing modules
- Create additional modules (STL, OOP, Concurrency)
- Improve existing code with modern C++ features
- Add unit tests for examples
- cppreference.com - Comprehensive C++ reference
- C++ Core Guidelines - Best practices
- Compiler Explorer - Online compiler and assembly viewer
This project is licensed under the MIT License - see the LICENSE file for details.
Happy Learning! π Start with introduction/Test.cpp
and work your way through each module systematically.