Programming is not about memorising syntax. It is about breaking a problem into small steps a computer can follow. This repository is a hands-on walk through those building blocks in C++, from the first variable to pointers, files and a small game.
Every program is short, commented and runs on its own. Read it, run it, then change something and see what happens. That loop is how programming actually gets learned.
| # | Topic | What it covers | Program |
|---|---|---|---|
| 01 | Basics | Variables, data types, sizeof, constants, type casting, input validation, formatted output |
variables_and_data_types.cpp, input_output.cpp |
| 02 | Operators | Arithmetic, relational, logical, bitwise, assignment, pre/post increment, ternary | operators.cpp |
| 03 | Conditionals | if/else if ladders, nested if, switch with fall-through |
conditionals.cpp |
| 04 | Loops | for, while, do-while, break/continue, nested-loop patterns |
loops.cpp |
| 05 | Functions | Pass by value / reference / pointer, default arguments, overloading, static locals, scope |
functions.cpp, number_utilities.cpp |
| 06 | Recursion | Base cases, memoization, fast power, Tower of Hanoi, backtracking permutations | recursion.cpp |
| 07 | Arrays | 1D traversal, searching, reversing, rotating, frequency tables; 2D matrix operations | arrays_1d.cpp, matrix_2d.cpp |
| 08 | Strings | C-strings vs std::string, palindromes, word reversal, find & replace, character frequency |
strings.cpp |
| 09 | Pointers | Addresses, dereferencing, pointer arithmetic, const pointers, new/delete, jagged arrays |
pointers.cpp |
| 10 | Structures | struct, nested structs, enum class, arrays of records, sorting records |
student_records.cpp |
| 11 | File handling | Writing, appending, reading line by line, parsing CSV, counting words | file_io.cpp |
| 12 | Sorting & searching | Bubble, selection, insertion, merge and quick sort with comparison counts; linear and binary search | sorting_searching.cpp |
| ★ | Project | Two-player Tic-Tac-Toe that ties arrays, functions, loops and input validation together | tic_tac_toe.cpp |
The topics are in learning order. Each one uses only what came before it.
You need a C++17 compiler: g++ (Linux, WSL, or MinGW on Windows), clang++ (macOS), or Visual Studio.
Build everything at once (Linux, macOS, WSL):
git clone https://github.com/BigB-904/programming-fundamentals-cpp.git
cd programming-fundamentals-cpp
make # every program is built into build/
./build/04-loops/loops # run oneCompile a single file:
g++ -std=c++17 -Wall 06-recursion/recursion.cpp -o recursion
./recursionEvery program builds cleanly with -Wall -Wextra -pedantic.
- Predict before you run. Guess the output, then check. Where you guessed wrong is where the learning is.
- Break things on purpose. Remove a base case, go one past the end of an array, forget a
delete[], and see what the compiler or the program does. - Re-write from memory. Close the file and write the function again. If you can't, you've found what to review.
- Extend it. Add a vote counter to the records program, an AI player to Tic-Tac-Toe, or a new sorting algorithm with its own comparison count.
MIT: use it, learn from it, share it.