C++ exercises
Exercises with full test sets for C++ are being written and verified. Until they are published, every lesson ends with a short program to write, with its expected output.
- C++ Syntax and Your First ProgramHow a C++ program is put together: #include, main(), statements, blocks and std::cout, plus how to compile and run it with g++ -std=c++17.8 min
- Variables and Types in C++Declaring C++ variables with int, double, char, bool and std::string, initialising them, using const and auto, and why an uninitialised variable is a bug.9 min
- Operators in C++C++ arithmetic, comparison, logical and assignment operators: integer division and modulo, prefix versus postfix ++, short-circuit evaluation and precedence.9 min
- Conditions in C++: if, else and switchHow C++ chooses between paths with if, else if and else, switch with break, the ?: operator and the C++17 if with an initialiser, with runnable examples.8 min
- Loops in C++: for, while and do-whileC++ loops explained: the three parts of a for loop, while and do-while, reading input until it ends, nested loops, and when to reach for break or continue.9 min
- Functions in C++Defining and calling C++ functions: return types, parameters, prototypes, pass by value versus by reference, default arguments and overloading, with examples.10 min