Beginner's Guide To C++ Beginner's Guide Beginner's Guide

    Introduction Intro

    What Is This Guide? About

    • an organized collection of links to topic articles
    • about learning modern, idiomatic C++
    • (roughly) ordered by increasing level of C++ proficiency (top to bottom)
    • many articles are based on slide decks taken from an undergraduate C++ crash course

    What Should I Already Know? Required Knowledge

    You should know how to use a command line and should have a basic understanding of fundamental imperative programming concepts, like

    • variables   (int i = 0, var x = 0, … )
    • conditional branching   (if, then, else, … )
    • loops   (for, while, repeat, … )
    • functions / subroutines   (int main(), fn main, … )

    It certainly helps if you are already somewhat familiar with other programming languages like Python or Java. You should be aware however, that C++ is very different from Java or C# despite the superficial syntactic similarities.

    What is C++? — Why C++? What is C++? C++?

    Predictable Resource Control
    "direct map to hardware": CPU, memory, …
    Zero-Overhead Abstractions
    "you only pay for what you use"
    • deterministic object lifetime
    • value semantics for all types
    • custom types can behave exactly like built-in types
    • full control down to individual bits
    C++98 1998 the original standard
    C++11 2011 almost a new language modern C++
    C++14 2014 some improvements
    C++17 2017 new features & library extensions
    C++20 2020 game-changing new features & libraries
    • if memory consumption is critical
    • if runtime is critical
    • if latency is critical
    • if power consumption is critical
    • OS level programming
    • embedded systems
    • large-scale, massively parallel systems
    • source-code portability across architectures
    • "scripting" & rapid prototyping
    • GUIs with trivial internal logic

    C++ Compared to… C++ vs.

    C++ C
    not a strict subset of C++
    stronger type system weak type system
    high-level abstractions only low-level memory abstraction
    powerful custom types (classes) only data aggregation (struct)
    use compiler as correctness checker get the code to compile quickly
    if it compiles, it should be correct debugging is the real work
    C++ Java
    value semantics for all types value semantics only for primitives (int, float,… )
    optional reference semantics for all types baked-in reference semantics for class types
    full control over memory (de-)allocation; no garbage collection garbage collector; can degrade performance
    deterministic & controllable object lifetime no predictable object lifetime control
    ⇒ memory frugal ⇒ high memory consumption
    aggressive inlining can eliminate slow function calls performance degradation due to un-devirtualizable, non-inlinable methods
    C++ Python
    almost always faster almost always slower (in practice around 25-50 times)
    complex syntax and tons of features can be intimidating to newcomers simple syntax; usually easy to comprehend
    statically typed dynamically typed
    many types of bugs can be caught at compile time many types of bugs will only manifest at runtime
    suited for safety-critical lange-scale systems hard to build reliable large-scale systems
    even simple, small-scope tasks can quickly require an expert knowledge of various arcane corner cases & quirks tends to be more beginner-friendly and small scripts are usually quickly written
    fairly small standard library but extensive ecosystem with libraries for nearly everything batteries included philosophy with tons of libraries only one import away

    Learning Resources Resources

    First Steps

    Input & Output

    Basic Custom Types

    Diagnostics

    Terms
    warnings are compiler messages hinting at potentially problematic runtime behavior / subtle pitfalls
    static analysis finds potential runtime problems like undefined behavior by analyzing the source code
    dynamic analysis finds potential problems like memory leaks by running the actual program
    profiling is used to find out how much each function/loop/code block contributes to the total running time, memory consumption, …
    debugging is used to step through code at runtime and inspect in-memory values
    testing compare actual and expected behavior of parts or entire program
    code coverage tells what parts of the code are actually executed / subjected to testing

    Standard Library Overview Standard Library Std.Library

    Code Organization


    Separate Compilation In One Image (click to enlarge)

    Powerful Custom Types

    Generic Programming

    Memory Management

    Software Design Basics