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.

Jun 18: We’ve added a new chapter 8, focused on type conversion and function overloading. A few lessons from chapters 6, 11, and 19 have been moved as a result. Enjoy!

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 and the scope resolution operator
6.3Local variables
6.4Introduction to global variables
6.5Variable shadowing (name hiding)
6.6Internal linkage
6.7External linkage
6.8Why (non-const) global variables are evil
6.9Sharing global constants across multiple files (using inline variables)
6.10Static local variables
6.11Scope, duration, and linkage summary
6.12Using declarations and using directives
6.13Unnamed and inline namespaces
6.xChapter 6 summary and quiz
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

Jun 18: Chapter 8 is newly added.

Chapter 8Type Conversion and Function Overloading
8.1Implicit type conversion (coercion)
8.2Floating-point and integral promotion
8.3Numeric conversions
8.4Arithmetic conversions
8.5Explicit type conversion (casting) and static_cast
8.6Typedefs and type aliases
8.7Type deduction for objects using the auto keyword
8.8Type deduction for functions
8.9Introduction to function overloading
8.10Function overload differentiation
8.11Function overload resolution and ambiguous matches
8.12Default arguments
8.13Function templates
8.14Function template instantiation
8.15Function templates with multiple template types
8.xChapter 8 summary and quiz
Chapter 9Compound Types (under construction)
9.1Using a language reference
9.2Enumerated types
9.3Enum classes
9.5Random number generation
9.xChapter 9 summary and quiz
Chapter 10Arrays, Strings, Pointers, and References
10.1Arrays (Part I)
10.2Arrays (Part II)
10.3Arrays and loops
10.4Sorting an array using selection sort
10.5Multidimensional Arrays
10.6C-style strings
10.7An introduction to std::string_view
10.8Introduction to pointers
10.9Null pointers
10.10Pointers and arrays
10.11Pointer arithmetic and array indexing
10.12C-style string symbolic constants
10.13Dynamic memory allocation with new and delete
10.14Dynamically allocating arrays
10.15Pointers and const
10.16Reference variables
10.17References and const
10.18Member selection with pointers and references
10.19For-each loops
10.20Void pointers
10.21Pointers to pointers and dynamic multidimensional arrays
10.22An introduction to std::array
10.23An introduction to std::vector
10.24Introduction to iterators
10.25Introduction to standard library algorithms
10.xChapter 10 comprehensive quiz
Chapter 11Functions
11.1Function parameters and arguments
11.2Passing arguments by value
11.3Passing arguments by reference
11.4Passing arguments by address
11.5Returning values by value, reference, and address
11.6Inline functions
11.7Function Pointers
11.8The stack and the heap
11.9std::vector capacity and stack behavior
11.11Command line arguments
11.12Ellipsis (and why to avoid them)
11.13Introduction to lambdas (anonymous functions)
11.14Lambda captures
11.xChapter 11 comprehensive quiz
Chapter 12Basic Object-oriented Programming
12.1Welcome to object-oriented programming
12.2Classes and class members
12.3Public vs private access specifiers
12.4Access functions and encapsulation
12.6Constructor member initializer lists
12.7Non-static member initialization
12.8Overlapping and delegating constructors
12.10The hidden “this” pointer
12.11Class code and header files
12.12Const class objects and member functions
12.13Static member variables
12.14Static member functions
12.15Friend functions and classes
12.16Anonymous objects
12.17Nested types in classes
12.18Timing your code
12.xChapter 12 comprehensive quiz
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.17Overloading operators and function templates
13.xChapter 13 comprehensive quiz
Chapter 14Reserved for Future Reorganization
Chapter 15Reserved for Future Reorganization
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 and Classes
19.1Template classes
19.2Template non-type parameters
19.3Function template specialization
19.4Class template specialization
19.5Partial template specialization
19.6Partial 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
B.4Introduction to C++20
Appendix CThe End
C.1The end?