beginner · c++

Modern C++ Foundations

Learn the core syntax, types, control flow, functions, and object-oriented principles of C++. Progress to memory management, standard library containers, algorithms, templates, and modern resource-safe design.

What you could build

  • Create a command-line unit converter using functions, conditionals, and numeric types.
  • Develop a text-based inventory tracker using classes and standard library containers.
  • Implement a contact search tool with strings, vectors, maps, and algorithms.
  • Build a file-based word frequency analyzer using streams and associative containers.
  • Create a small expression evaluator that combines parsing, classes, and error handling.

You pick the project at the start — these are examples, not a fixed list.

What you'll be able to do

  • Trace a complete C++ program from source structure through variables, expressions, functions, control flow, input, and output, and explain exactly what it does.
  • Choose appropriate parameter-passing methods, including values, references, and const references, while predicting how arrays and structures change across function calls.
  • Define classes with constructors, access control, member functions, and const correctness, then reason about the state of multiple objects.
  • Analyze object lifetimes, pointers, dynamic allocation, RAII, move semantics, and smart-pointer ownership to identify resource leaks and ownership transfers.
  • Use modern standard-library tools and language features—including vectors, maps, algorithms, lambdas, string_view, span, optional, templates, concepts, and constexpr—to reason about types, lifetimes, and results.

Who this is for

This course is for learners who want a structured introduction to C++ or need to solidify core language knowledge before tackling larger codebases. It fits aspiring software developers, programmers coming from another language, and technically curious learners who want to understand modern, resource-safe C++.

What you should already know

  • Basic arithmetic and familiarity with Boolean ideas such as true, false, comparisons, and logical conditions.
  • Comfort creating or editing plain-text files and running code in a C++ compiler or online coding environment.

How a lesson actually goes

Lesson 1
TutorWelcome to Modern C++ Foundations. We will begin by looking at how a small C++ program is organized and how source code becomes an executable. Consider this program: int main() { return 0; }. What do you think each part contributes?
YouI think main is the program, and return 0 stops it. I am not sure why there are two sets of parentheses or what the braces do.
TutorThat is a useful starting distinction: main is a function, not the entire program, and execution begins by calling that function. The parentheses hold its parameter list—empty here—and the braces mark the function body, the statements that run when main is called.
YouSo the braces are like a block of instructions, and return 0 sends a value back when the function finishes. Does the compiler run the source file directly?
TutorExactly: the braces delimit the instructions, and the returned integer conventionally indicates successful completion to the operating system. The compiler usually translates the source into object code, and a linker combines that with needed library code to produce the executable; I will next have you identify those stages in a slightly larger example.

Written from this course's first lesson to show the format — not a recording of a real session.

Course content

marks each module's capstone lesson.

01C++ Essentials11 lessons

Build a foundation in C++ program structure, values, expressions, input and output, control flow, and functions, then synthesize these concepts to reason about complete small programs.

  • Course Introduction

    Welcome and orientation: overview of the learning path, key outcomes, and how modules build from C++ fundamentals toward modern resource-safe design.

  • Program Structure

    Introduces source files, the main function, statements, braces, semicolons, and the compile-and-run process that turns C++ source into a program.

  • Variables

    Explains variables as named storage locations, including declaration, initialization, assignment, and basic local scope.

  • Fundamental Types

    Covers common built-in types such as int, double, char, and bool, along with the kinds of values they represent and their basic limitations.

  • Expressions

    Introduces operands, operators, arithmetic calculations, comparisons, Boolean logic, and the order in which compound expressions are evaluated.

  • Output

    Explains console output with std::cout, stream insertion, line breaks, and the relationship between values and their textual representation.

  • Input

    Covers std::cin, extraction into variables, basic input sequencing, and how formatted extraction handles whitespace and invalid input situations.

  • Conditionals

    Introduces conditional control flow, including branch ordering, Boolean conditions, nested decisions, and the distinction between separate and mutually exclusive paths.

  • Loops

    Explains repetition through loop conditions, counters, iteration, termination, and the differences among C++ loop forms.

  • Functions

    Covers function declarations and definitions, parameters, return types, calls, and local function scope as tools for organizing reusable behavior.

  • Essential Syntax Synthesis

    Assesses integrated reasoning about foundational C++ syntax and execution, including tracing values, control flow, function calls, and program output.

02Control Flow8 lessons

Extend foundational control-flow knowledge with alternative selection, short-circuit evaluation, explicit transfers, nested execution, and techniques for reasoning about repeated computation.

  • Switch Statements

    A switch statement compares one expression with multiple case labels and executes the matching branch. Learners examine case grouping, break behavior, and the default branch.

  • Short-Circuit Evaluation

    Logical operators may skip evaluation of their right-hand operand when the result is already determined. This behavior affects both program flow and whether operand side effects or errors occur.

  • Break Statements

    The break statement immediately exits the nearest enclosing loop or switch statement. Learners trace the statements skipped by the transfer and the next statement that executes.

  • Continue Statements

    The continue statement abandons the current iteration without exiting the loop. Its exact next step depends on whether it appears in a while, do-while, or for loop.

  • Early Returns

    An early return ends the current function before its remaining statements execute. Learners distinguish returned values from discarded paths and identify the caller statement that resumes execution.

  • Nested Control Flow

    Nested control flow places one selection or repetition construct inside another, so the inner path is evaluated only when the enclosing path reaches it. Learners track active conditions, iterations, and the nearest enclosing transfer target.

  • Loop Invariants

    A loop invariant is a condition that is established before iteration and preserved by every completed iteration. It provides a structured way to reason about initialization, progress, and termination.

  • Control Flow Synthesis

    This synthesis assessment requires tracing and justifying control flow across interacting statements and function boundaries. Learners use precise execution traces and invariant-based reasoning to explain both ordinary and skipped paths.

03Functions and Data9 lessons

Deepen function design by examining signatures, parameter passing, references, and const correctness, then apply these ideas to arrays and structures as organized forms of data.

  • Function Signatures

    A function signature describes how a function can be called and how its inputs and output are typed. Learners distinguish declarations from definitions and use signatures to determine whether a call is well-formed.

  • Pass-by-Value

    Pass-by-value gives a function its own parameter object initialized from the argument. Learners reason about independent storage, copied values, and the resulting behavior of modifications inside the function.

  • Reference Parameters

    A reference parameter provides an alternate name for an existing object rather than an independent copy. Learners trace aliasing and explain how assignments through a reference affect the referenced object.

  • Const References

    A const reference combines aliasing with a restriction against mutation through the parameter. Learners determine which arguments can bind to it and why it is useful for inspecting data without copying or changing it.

  • Arrays

    A built-in array stores a fixed number of elements of one type in indexed positions. Learners connect array size, zero-based indexing, initialization, and element access to determine valid and invalid operations.

  • Array Parameters

    When built-in arrays are used as function arguments, the function generally receives access to the array's elements rather than a complete copied array. Learners reason about element modification, index bounds, and the need to communicate the array length.

  • Structures

    A structure defines a custom type whose named members can hold values of different types. Learners interpret structure declarations, construct objects of the type, and access or update individual members.

  • Structured Data Parameters

    Structures can be passed to functions by value, by non-const reference, or by const reference, with different effects on copying and mutation. Learners compare these interfaces and trace how member changes move between caller and callee.

  • Functions and Data Synthesis

    This synthesis assesses how function signatures govern calls and how values, references, arrays, and structures move through a program. Learners trace execution, identify mutations and independent copies, and justify whether each access remains within valid data boundaries.

04Classes and Objects9 lessons

Develop an object-oriented foundation by defining classes, creating objects, organizing state and behavior, controlling access, and using constructors and const member functions to express safe interfaces.

  • Class Definitions

    A class is a user-defined type whose declaration describes the data and operations that its objects can contain. Learners distinguish a class definition from the objects created from it.

  • Objects

    An object is an instance of a class with its own storage for the class's non-static data. Learners reason about how multiple objects of the same class can hold different values.

  • Data Members

    Data members represent the state stored by each object. Learners identify member declarations and determine which object's state changes when a data member is accessed or updated.

  • Member Access

    The member-access operator selects a member from a particular object. Learners trace expressions such as object.member and distinguish the selected object from the selected member.

  • Member Functions

    Member functions define behavior associated with a class and can directly access that object's members. Learners trace how a call supplies an implicit object context in addition to any explicit arguments.

  • Constructors

    A constructor is a special member function that runs when an object is created. Learners distinguish constructor calls from ordinary member-function calls and trace initialization of newly created objects.

  • Access Control

    Access control determines which code may use a class member directly. Learners distinguish a class's public interface from its private implementation details and identify invalid access attempts.

  • Const Member Functions

    A const member function promises not to modify the observable state of the object through that function. Learners determine which calls are valid for const and non-const objects and why.

  • Classes and Objects Synthesis

    This synthesis assesses how class definitions become objects with independent state and controlled behavior. Learners explain the exact execution and validity of code that combines data members, member functions, constructors, access control, and const member functions.

05Memory and Resources13 lessons

Understand how C++ represents storage, addresses, pointers, and object lifetimes, then apply ownership, destructors, RAII, move semantics, and smart pointers to reason about resource-safe program behavior.

  • Storage Duration

    Storage duration describes how long storage for an object exists during program execution. Learners classify objects by when their storage is created and released.

  • Object Lifetime

    An object's lifetime is the interval during which it can be used as a valid object. Learners relate lifetime boundaries to initialization, scope, and destruction.

  • Address-of Operator

    The address-of operator produces a pointer value that identifies where an object is stored. Learners distinguish an object from the address associated with that object.

  • Pointers

    A pointer is an object that stores an address and has a type describing the kind of object it can point to. Learners trace pointer assignments and distinguish pointer variables from their targets.

  • Dereferencing

    Dereferencing follows a pointer to the object at its stored address. Learners determine when dereferencing reads or modifies the pointed-to object and recognize the requirement for a valid pointer.

  • Null Pointers

    nullptr is the null pointer value used to express that a pointer has no target. Learners test pointers before dereferencing and distinguish null from a valid address.

  • Dynamic Allocation

    Dynamic allocation obtains storage whose lifetime is not tied directly to a local scope. Learners match allocation and deallocation operations and identify leaks and invalid repeated releases.

  • Destructors

    A destructor is a class operation that runs when an object is destroyed. Learners trace destructor calls at the end of an object's lifetime and connect them to cleanup.

  • RAII

    Resource Acquisition Is Initialization represents a resource with an object whose destructor performs release. Learners reason about how scope exit, including exceptional or early control flow, triggers cleanup.

  • Move Semantics

    Move semantics allows an object to transfer ownership of resources from a source object to a destination object. Learners identify moved-from states and distinguish moving from copying.

  • Unique Ownership

    std::unique_ptr manages one dynamically allocated object with a single owner and releases it automatically. Learners reason about automatic cleanup, null states, and move-only ownership transfer.

  • Shared Ownership

    std::shared_ptr represents shared ownership through a reference count. Learners determine how copying, resetting, and destroying shared_ptr instances affect the count and resource lifetime.

  • Memory and Resources Synthesis

    This synthesis evaluates whether learners can connect memory representation with resource ownership and lifetime management. Learners explain exact behavior, identify unsafe operations, and justify resource-safe alternatives.

06Standard Library Tools11 lessons

Use common C++ standard library types and tools to represent text and collections, traverse data, and apply reusable algorithms with callable conditions.

  • Standard Library Headers

    Standard library facilities are organized into headers that must be included before their declarations can be used. Learners distinguish header inclusion from using a facility in the std namespace.

  • Namespaces

    Namespaces organize declarations and prevent unrelated names from colliding. Standard library facilities are generally accessed with the std:: qualifier.

  • std::string

    std::string manages sequences of characters while providing useful operations for construction, concatenation, indexing, length queries, and comparison. Its value semantics make text safer and more convenient than raw character arrays for typical use.

  • std::vector

    std::vector stores elements contiguously while allowing its size to grow and shrink. Learners reason about element access, size, and operations that add or remove elements.

  • std::array

    std::array wraps a fixed-size sequence in a standard library type with predictable value semantics and container operations. Its size is part of its type and does not change during execution.

  • std::map

    std::map associates ordered unique keys with values and maintains those associations as elements are inserted or removed. Learners distinguish key lookup from positional indexing and reason about missing keys.

  • Iterators

    Iterators provide a generalized way to identify and traverse elements in standard library containers. The end iterator marks a position past the final element and must not be dereferenced.

  • Algorithms

    The standard algorithm library provides reusable operations over iterator ranges, separating common computations from container implementations. Learners match algorithm behavior to an input range and interpret its result.

  • Lambda Expressions

    A lambda expression creates an unnamed callable that can be passed directly to standard algorithms. Its parameter list, return behavior, and capture clause determine how it computes and what outside state it can access.

  • Range-Based For

    Range-based for provides concise traversal over the elements of a compatible range. The element declaration controls whether each iteration copies an element, refers to it, or accesses it read-only.

  • Standard Library Synthesis

    This synthesis assesses the coordinated use of standard library tools for representing text and collections, traversing elements, and performing reusable computations. Learners trace the program's data flow, algorithm effects, callable behavior, and final values.

07Modern C++ Synthesis10 lessons

Apply modern C++ language and library features to express initialization, type relationships, non-owning views, optional values, and generic interfaces with clear ownership and lifetime reasoning.

  • Type Deduction

    Type deduction with auto reduces repeated type declarations while preserving important const, reference, and value behavior. Learners trace which type the compiler deduces from an initializer.

  • Uniform Initialization

    Brace initialization provides a consistent syntax for initializing fundamental values, aggregates, and objects. Its narrowing-conversion checks make unintended data loss easier to detect.

  • Structured Bindings

    Structured bindings unpack selected elements of pairs, tuples, arrays, and suitable user-defined types into named bindings. Their declaration form controls how the underlying elements are accessed.

  • std::string_view

    std::string_view is a lightweight, non-owning view of contiguous characters. Learners distinguish viewing text from owning a std::string and reason about invalidation and dangling views.

  • std::span

    std::span represents a non-owning view over contiguous elements such as arrays, vectors, or other compatible storage. It separates sequence access from ownership while retaining size information.

  • std::optional

    std::optional expresses the distinction between a present value and no value without requiring a sentinel value or raw pointer. Learners use presence checks and safe value access.

  • Function Templates

    Function templates describe a family of functions whose parameter and return types are determined for particular calls. Learners connect template parameters, deduction, instantiation, and type-specific operations.

  • Concepts

    Concepts express named or inline requirements on template arguments. They make generic interfaces communicate supported operations and reject unsuitable types earlier and more clearly.

  • Constexpr Evaluation

    constexpr permits eligible values and functions to participate in constant evaluation while remaining usable at runtime when necessary. Learners identify the requirements and observable consequences of compile-time computation.

  • Modern C++ Synthesis

    This synthesis assesses how modern language and library features interact in complete C++ code. Learners trace type deduction, generic constraints, ownership boundaries, view lifetimes, absent values, and compile-time versus runtime execution.

Questions

Do I need prior C++ experience?

No. The course begins with program structure, variables, types, expressions, input, output, conditionals, loops, and functions. Experience in another programming language can help, but it is not required.

How far beyond beginner syntax does the course go?

It progresses through classes, object lifetimes, pointers, dynamic allocation, RAII, move semantics, smart pointers, standard containers and algorithms, templates, concepts, and modern non-owning views such as std::string_view and std::span.

Will the course explain memory management clearly?

Yes. You will trace storage duration and object lifetime, use pointers and nullptr, understand new and delete, and compare manual ownership with RAII, std::unique_ptr, and std::shared_ptr.

Does the course cover the C++ standard library?

Yes. It covers headers, namespaces, strings, vectors, arrays, maps, iterators, algorithms, lambdas, and range-based for statements, then uses them in synthesis exercises.

Will I learn modern C++ features or only older syntax?

The foundation includes classic syntax and manual memory concepts so you can understand existing code, then advances to modern practices and features such as auto, uniform initialization, structured bindings, optional, concepts, constexpr, move semantics, and resource-safe ownership.

How does the one-on-one AI tutor affect the lessons?

The tutor can ask you to predict code behavior, check your reasoning, identify the exact misconception in a partial answer, and adjust explanations and follow-up questions as you progress.

The first lesson is ten minutes away.

Free while codeset is early. You choose what you're building before the first lesson starts, and the course is taught around it.

Start this course

Other courses