Beginner's Guide To C++ Beginner's Guide Beginner's Guide
In a hurry? Start with the Hello World
!
- 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
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.
Predictable Resource Control
"direct map to hardware": CPU, memory, …
"direct map to hardware": CPU, memory, …
Zero-Overhead Abstractions
"you only pay for what you use"
"you only pay for what you use"
- multi-paradigm: value-oriented, procedural, generic, functional, object-oriented
- value semantics by default
- custom types can behave exactly like built-in types
- deterministic object lifetime
- precise memory control down to individual bits
ISO Standard C++
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 |
Where it does and doesn't shine
- 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
See Also
C
C++ | C |
---|
not a strict subset of C++ | |
stronger type system | weak type system |
high-level abstractions | only low-level memory abstraction |
typed compile-time programming | only untyped macros for compile-time programming |
powerful custom types (class es) |
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 |
Java
C++ | Java |
---|
multi-paradigm: value-oriented, procedural, generic, functional, object-oriented | mainly object-oriented, some functional and generic aspects |
value semantics by default for fundamental & custom types |
value semantics
only for primitives (int , float ,… ) |
optional reference semantics for all types | baked-in reference semantics for class types |
precise 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 |
Python
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 includedphilosophy with tons of libraries only one import away |
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 |