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 advanced concepts using modern C++20+ standards.
This repository contains 13 comprehensive modules covering essential C++ programming concepts:
- 120+ practical examples across different difficulty levels
- Self-contained lessons - each
.cppfile compiles independently - Modern C++ practices (C++20+ standards)
- Real-world applications and exercises
- Progressive difficulty from basics to advanced OOP concepts
# 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_demoFolder: 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
Folder: file/
text_file_read.cpp&text_file_wirte.cpp- Text file operationstext_user_read.cpp&text_user_wirte.cpp- User data file handlingbainary_product_read.cpp&bainary_product_write.cpp- Binary file operationsbainary_woker_write.cpp- Binary worker data storage
Key Concepts: File streams, text vs binary files, file I/O operations
Folder: oop/
class_object.cpp- Basic class and object creationcontructor.cpp&destructor.cpp- Constructor and destructor methodsset_get.cpp- Getter and setter methodskeyword_this.cpp- Using the 'this' pointerfriend_class.cpp&friend_function.cpp- Friend relationshipsstatic_method.cpp- Static methods and variablesinline_method.cpp- Inline function optimizationnested_class.cpp- Classes within classespointer.cpp&pointer_two.cpp- Object pointers
- Advanced inheritance concepts and implementations
- Virtual functions and polymorphic behavior
Key Concepts: Classes, objects, encapsulation, inheritance, polymorphism
Folder: union/
test.cpp- Basic union operationsobject.cpp- Union with objects
Key Concepts: Memory-efficient data types, unions vs structs
Folder: project/
project.cpp- Main project demonstrationproduct.cpp- Product management systemStudens.cpp- Student management systemmoney.cpp- Financial calculationsDelivery_Fee.cpp- Delivery cost calculatorHybrid_Inheritance.cpp- Advanced OOP inheritance examplecolor.h- Color utility header
Key Concepts: Project organization, real-world applications, system integration
# 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 -DNDEBUGCreate 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
- Learn
file/- master file input/output operations - Dive into
oop/- master object-oriented programming concepts - Optimize with
union/- understand unions and memory optimization - Build
project/- apply your skills in real-world projects
- 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
- Chat Application (OOP + File I/O): Real-time messaging app
- Image Viewer (OOP + Templates): View and edit images
- Custom Shell (pointers + file I/O): Build a simple command-line shell
# Compiler not found
xcode-select --install
# Permission denied
chmod +x ./build/program_name
# Memory errors
# Recompile with: -fsanitize=address,undefined -g- Use
clang-formatfor consistent formatting - Enable
clang-tidyfor 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
- Module 10: Object-Oriented Programming (OOP)
- Module 11: File Input/Output
- Module 12: Unions & Bit Fields
- Module 13: Project Examples
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.