C++ for Beginners
From your first program to classes, smart pointers, templates and a final project. Auto-checked exercises run right in your browser.
- Built-in types and their sizesTheory
- Initialization: =, () and {}Theory
- Quiz — which initialization fails to compileQuiz
- const and constexprTheory
- Quiz — what can be changedQuiz
- Exercise: temperature conversionExercise
- auto, scope and lifetimeTheory
- Quiz — which variable is visibleQuiz
- Quiz — static inside a functionQuiz
- Exercise: call counterExercise
- Arithmetic: integer division, remainder, overflowTheory
- Quiz — 7 / 2 and −7 % 3Quiz
- Comparisons, logic, ++ and --Theory
- Quiz — whether the function is calledQuiz
- Bitwise operators, ternary and precedenceTheory
- Quiz — operator precedenceQuiz
- Exercise: digit sum of a three-digit numberExercise
- Exercise: bit flagsExercise
- Declaration and definitionTheory
- Parameters: by value and by referenceTheory
- Quiz — copy or referenceQuiz
- Quiz — a reference to a local variableQuiz
- Exercise: swap two valuesExercise
- Overloading and default argumentsTheory
- Quiz — which overload the compiler picksQuiz
- Exercise: shape areasExercise
- Lambdas: a first lookTheory
- Quiz — what the lambda capturesQuiz
- Exercise: GCD and LCMExercise
- References, lvalues and rvaluesTheory
- Pointers, addresses and nullptrTheory
- Quiz — reference or pointerQuiz
- Quiz — a function returning a pointerQuiz
- const T* and T* constTheory
- Quiz — what is const hereQuiz
- Exercise: min and max through referencesExercise
- Exercise: find an element, return a pointerExercise
- std::vectorTheory
- Quiz — size and capacityQuiz
- map, set and unordered_mapTheory
- Quiz — operator[] on a mapQuiz
- IteratorsTheory
- Quiz — an iterator after push_backQuiz
- Quiz — erasing in a loopQuiz
- Choosing a containerTheory
- Exercise: remove duplicatesExercise
- Exercise: word frequenciesExercise
- Exercise: transpose a matrixExercise
- Complexity: O(1), O(n), O(n log n)Theory
- Quiz — which complexityQuiz
- sort, find, count, accumulate and lambdasTheory
- Quiz — a comparator for sortQuiz
- Binary search and recursionTheory
- Quiz — the base case of recursionQuiz
- Exercise: binary searchExercise
- Exercise: sort by keyExercise
- Exercise: fast exponentiationExercise
- struct, class and accessTheory
- Constructors and the member initializer listTheory
- Quiz — field initialization orderQuiz
- Destructor, rule of zero, const methodsTheory
- Quiz — a const methodQuiz
- Exercise: bank accountExercise
- InheritanceTheory
- virtual, override and polymorphismTheory
- Quiz — a derived object by valueQuiz
- Quiz — what override checksQuiz
- Quiz — dynamic_castQuiz
- Exercise: shapes with a virtual areaExercise
- Exercise: IntStack classExercise
- Stack and heap; new and deleteTheory
- Quiz — using an object after deleteQuiz
- Quiz — virtual destructorQuiz
- RAIITheory
- Quiz — new and an early returnQuiz
- std::unique_ptr and std::moveTheory
- Quiz — unique_ptrQuiz
- std::shared_ptr and weak_ptrTheory
- Quiz — shared_ptrQuiz
- Exercise: ScopeGuardExercise
- Exercise: owning buffer on unique_ptrExercise
- Exercise: playlist of shared songsExercise
- Function templatesTheory
- Template argument deductionTheory
- Quiz — argument deductionQuiz
- Exercise: generic maxExercise
- Class templates and specializationTheory
- Quiz — templatesQuiz
- Quiz — which specialization is chosenQuiz
- Exercise: Pair templateExercise
- Variadic templates: a first lookTheory
- Quiz — sizeof...Quiz
- Exercise: a running sumExercise
- Threads: why and howTheory
- Quiz — a forgotten joinQuiz
- Data races, mutexes and lock_guardTheory
- Quiz — what is wrong with ++counterQuiz
- Quiz — where the mutex is releasedQuiz
- Quiz — two mutexes in opposite orderQuiz
- std::atomicTheory
- async, future and time: chronoTheory
- Quiz — when std::async runsQuiz
- Exercise: countdown timerExercise