The C++ Tutorial is a free website devoted to teaching you how to program in C++. Whether you’ve had any prior programming experience or not, the tutorials on this site will walk you through all the steps to write, compile, and debug your C++ programs, all with plenty of examples.

Becoming an expert won’t happen overnight, but with a little patience, you’ll get there. And will show you the way.

Apr 12: We’ve re-enabled CDN caching, so the site should load about a second faster. If you encounter stale pages, missing comments, etc… please report the issue so we can investigate. Thanks!

Having trouble remembering where you saw something? Not sure where to find something? Use our site index to find what you’re looking for!

Chapter 0Introduction / Getting Started
0.1Introduction to these tutorials
0.2Introduction to programming languages
0.3Introduction to C/C++
0.4Introduction to C++ development
0.5Introduction to the compiler, linker, and libraries
0.6Installing an Integrated Development Environment (IDE)
0.7Compiling your first program
0.8A few common C++ problems
0.9Configuring your compiler: Build configurations
0.10Configuring your compiler: Compiler extensions
0.11Configuring your compiler: Warning and error levels
0.12Configuring your compiler: Choosing a language standard
Chapter 1C++ Basics
1.1Statements and the structure of a program
1.3Introduction to objects and variables
1.4Variable assignment and initialization
1.5Introduction to iostream: cout, cin, and endl
1.6Uninitialized variables and undefined behavior
1.7Keywords and naming identifiers
1.8Whitespace and basic formatting
1.9Introduction to literals and operators
1.10Introduction to expressions
1.11Developing your first program
1.xChapter 1 summary and quiz
Chapter 2C++ Basics: Functions and Files
2.1Introduction to functions
2.2Function return values
2.3Introduction to function parameters and arguments
2.4Introduction to local scope
2.5Why functions are useful, and how to use them effectively
2.6Forward declarations and definitions
2.7Programs with multiple code files
2.8Naming collisions and an introduction to namespaces
2.9Introduction to the preprocessor
2.10Header files
2.11Header guards
2.12How to design your first programs
2.xChapter 2 summary and quiz
Chapter 3Debugging C++ Programs
3.1Syntax and semantic errors
3.2The debugging process
3.3A strategy for debugging
3.4Basic debugging tactics
3.5More debugging tactics
3.6Using an integrated debugger: Stepping
3.7Using an integrated debugger: Running and breakpoints
3.8Using an integrated debugger: Watching variables
3.9Using an integrated debugger: The call stack
3.10Finding issues before they become problems
3.xChapter 3 summary and quiz
Chapter 4Fundamental Data Types
4.1Introduction to fundamental data types
4.3Object sizes and the sizeof operator
4.4Signed integers
4.5Unsigned integers, and why to avoid them
4.6Fixed-width integers and size_t
4.7Introduction to scientific notation
4.8Floating point numbers
4.9Boolean values
4.10Introduction to if statements
An introduction to std::string
4.14Const, constexpr, and symbolic constants
4.xChapter 4 summary and quiz
Chapter 5Operators
5.1Operator precedence and associativity
5.2Arithmetic operators
5.3Modulus and Exponentiation
5.4Increment/decrement operators, and side effects
5.5Comma and conditional operators
5.6Relational operators and floating point comparisons
5.7Logical operators
5.xChapter 5 summary and quiz
Chapter OBit Manipulation (optional chapter)
O.1Bit flags and bit manipulation via std::bitset
O.2Bitwise operators
O.3Bit manipulation with bitwise operators and bit masks
O.4Converting between binary and decimal
Chapter 6Object Scope and Conversions
6.1Compound statements (blocks)
6.2User-defined namespaces
6.3Local variables
6.4Introduction to global variables
6.5Variable shadowing (name hiding)
6.6Internal linkage
6.7External linkage
6.8Global constants and inline variables
6.9Why global variables are evil
6.10Static local variables
6.11Scope, duration, and linkage summary
6.12Using declarations and using directives
6.13Typedefs and type aliases
6.14The auto keyword
6.15Implicit type conversion (coercion)
6.16Explicit type conversion (casting) and static_cast
6.17Unnamed and inline namespaces
6.xChapter 6 summary and quiz

Dec 21: Chapter 7 has been updated!

Chapter 7Control Flow and Error Handling
7.1Control flow introduction
7.2If statements and blocks
7.3Common if statement problems
7.4Switch statement basics
7.5Switch fallthrough and scoping
7.6Goto statements
7.7Intro to loops and while statements
7.8Do while statements
7.9For statements
7.10Break and continue
7.11Halts (exiting your program early)
7.12Introduction to testing your code
7.13Code coverage
7.14Common semantic errors in C++
7.15Detecting and handling errors
7.16std::cin and handling invalid input
7.17Assert and static_assert
7.xChapter 7 summary and quiz
Chapter 8Compound Types (under construction)
8.1Using a language reference
8.2Enumerated types
8.3Enum classes
8.5Random number generation
8.xChapter 8 summary and quiz
Chapter 9Arrays, Strings, Pointers, and References
9.1Arrays (Part I)
9.2Arrays (Part II)
9.3Arrays and loops
9.4Sorting an array using selection sort
9.5Multidimensional Arrays
9.6C-style strings
9.7An introduction to std::string_view
9.8Introduction to pointers
9.9Null pointers
9.10Pointers and arrays
9.11Pointer arithmetic and array indexing
9.12C-style string symbolic constants
9.13Dynamic memory allocation with new and delete
9.14Dynamically allocating arrays
9.15Pointers and const
9.16Reference variables
9.17References and const
9.18Member selection with pointers and references
9.19For-each loops
9.20Void pointers
9.21Pointers to pointers and dynamic multidimensional arrays
9.22An introduction to std::array
9.23An introduction to std::vector
9.24Introduction to iterators
9.25Introduction to standard library algorithms
9.xChapter 9 comprehensive quiz
Chapter 10Functions
10.1Function parameters and arguments
10.2Passing arguments by value
10.3Passing arguments by reference
10.4Passing arguments by address
10.5Returning values by value, reference, and address
10.6Inline functions
10.7Function overloading
10.8Default arguments
10.9Function Pointers
10.10The stack and the heap
10.11std::vector capacity and stack behavior
10.13Command line arguments
10.14Ellipsis (and why to avoid them)
10.15Introduction to lambdas (anonymous functions)
10.16Lambda captures
10.xChapter 10 comprehensive quiz
Chapter 11Basic object-oriented programming
11.1Welcome to object-oriented programming
11.2Classes and class members
11.3Public vs private access specifiers
11.4Access functions and encapsulation
11.6Constructor member initializer lists
11.7Non-static member initialization
11.8Overlapping and delegating constructors
11.10The hidden “this” pointer
11.11Class code and header files
11.12Const class objects and member functions
11.13Static member variables
11.14Static member functions
11.15Friend functions and classes
11.16Anonymous objects
11.17Nested types in classes
11.18Timing your code
11.xChapter 11 comprehensive quiz
Chapter 12Reserved for future expansion
Chapter 13Operator overloading
13.1Introduction to operator overloading
13.2Overloading the arithmetic operators using friend functions
13.3Overloading operators using normal functions
13.4Overloading the I/O operators
13.5Overloading operators using member functions
13.6Overloading unary operators +, -, and !
13.7Overloading the comparison operators
13.8Overloading the increment and decrement operators
13.9Overloading the subscript operator
13.10Overloading the parenthesis operator
13.11Overloading typecasts
13.12The copy constructor
13.13Copy initialization
13.14Converting constructors, explicit, and delete
13.15Overloading the assignment operator
13.16Shallow vs. deep copying
13.xChapter 13 comprehensive quiz
Chapter 14Reserved for future expansion
Chapter 15Reserved for future expansion
Chapter 16An introduction to object relationships
16.1Object relationships
16.6Container classes
16.xChapter 16 comprehensive quiz
Chapter 17Inheritance
17.1Introduction to inheritance
17.2Basic inheritance in C++
17.3Order of construction of derived classes
17.4Constructors and initialization of derived classes
17.5Inheritance and access specifiers
17.6Adding new functionality to a derived class
17.7Calling inherited functions and overriding behavior
17.8Hiding inherited functionality
17.9Multiple inheritance
17.xChapter 17 comprehensive quiz
Chapter 18Virtual Functions
18.1Pointers and references to the base class of derived objects
18.2Virtual functions and polymorphism
18.3The override and final specifiers, and covariant return types
18.4Virtual destructors, virtual assignment, and overriding virtualization
18.5Early binding and late binding
18.6The virtual table
18.7Pure virtual functions, abstract base classes, and interface classes
18.8Virtual base classes
18.9Object slicing
18.10Dynamic casting
18.11Printing inherited classes using operator<<
18.xChapter 18 comprehensive quiz
Chapter 19Templates
19.1Function templates
19.2Function template instances
19.3Template classes
19.4Template non-type parameters
19.5Function template specialization
19.6Class template specialization
19.7Partial template specialization
19.8Partial template specialization for pointers
19.xChapter 19 comprehensive quiz
Chapter 20Exceptions
20.1The need for exceptions
20.2Basic exception handling
20.3Exceptions, functions, and stack unwinding
20.4Uncaught exceptions and catch-all handlers
20.5Exceptions, classes, and inheritance
20.6Rethrowing exceptions
20.7Function try blocks
20.8Exception dangers and downsides
20.9Exception specifications and noexcept
20.xChapter 20 comprehensive quiz

Chapter MMove semantics and smart pointers
M.1Intro to smart pointers and move semantics
M.2R-value references
M.3Move constructors and move assignment
M.8Circular dependency issues with std::shared_ptr, and std::weak_ptr
M.xChapter M comprehensive review

Chapter 21The Standard Template Library
21.1The Standard Library
21.2STL containers overview
21.3STL iterators overview
21.4STL algorithms overview
Chapter 22std::string
22.1std::string and std::wstring
22.2std::string construction and destruction
22.3std::string length and capacity
22.4std::string character access and conversion to C-style arrays
22.5std::string assignment and swapping
22.6std::string appending
22.7std::string inserting
Chapter 23Input and output (I/O)
23.1Input and output (I/O) streams
23.2Input with istream
23.3Output with ostream and ios
23.4Stream classes for strings
23.5Stream states and input validation
23.6Basic file I/O
23.7Random file I/O
Appendix AMiscellaneous Subjects
A.1Static and dynamic libraries
A.2Using libraries with Visual Studio
A.3Using libraries with Code::Blocks
Appendix BC++ Updates
B.1Introduction to C++11
B.2Introduction to C++14
B.3Introduction to C++17
Appendix CThe end
C.1The end?