C++ Tutorial for Beginners

Video Lectures

Displaying all 78 video lectures.
Lecture 1
Introduction to C++ Programming
Play Video
Introduction to C++ Programming
The first of a series on how to program in C++. This video introduces C++ and explains a bit about what it is and what you need to get started.
Lecture 2
Installation
Play Video
Installation
A video on what to install to get started with C++. While I won't give specific instructions for your platform, in this video I'll explain what to install and where to find it. We'll take a look at compilers and IDEs and I'll tell you where to find my recommended choices.
Lecture 3
Hello World
Play Video
Hello World
Finally it's time to create a simple program in C++! In this video I'll show you how to generate one using your IDE and we'll begin to look at the meaning of all the various brackets and symbols. But don't panic -- we'll return to everything again later. For the moment, just try to create your own Hello World program after watching this video and you'll be doing great.

Installing a compiler and IDE: https://www.youtube.com/watch?v=O17TOOOVkgs

"Hello World" program: https://www.youtube.com/watch?v=HztSZsbvhRg

Outputting text: https://www.youtube.com/watch?v=1Enqpi4trl8
Lecture 4
Outputting Text
Play Video
Outputting Text
A tutorial on outputting text in C++. First we'll go through the main program one more time, then I'll explain how you can "print" (output) text in C++ using cout. Also, an important look at coding style.
Lecture 5
Variables
Play Video
Variables
This tutorial is on variables -- one of the basic building blocks of computer programs. We'll take a look at how to store numbers temporarily in your program, so you can add them together, output them later on and basically have your own enormous numberfest.
Lecture 6
Strings
Play Video
Strings
A tutorial on strings in C++. Strings are used to store bits of text, which you can output later or manipulate in various ways.
Lecture 7
User Input
Play Video
User Input
Now we can begin to make our program interactive, by getting input from the user. In this video we'll see how to use "cin" to get stuff that the user's typed in the console.
Lecture 8
Binary Numbers and Memory
Play Video
Binary Numbers and Memory
A brief discussion of the binary number system and what it has to do with computer memory. With C++, it's very helpful to know a little theoretical stuff, so we'll make a start here.
Lecture 9
Integer Variable Types
Play Video
Integer Variable Types
We'll take a closer look at C++'s integer variable types in this tutorial. Choosing the right size variable for your data is very important in C++, especially since C++ won't necessarily warn you if you choose a type that's too small -- your program just won't work properly!
Lecture 10
Floating Point Variable Types
Play Video
Floating Point Variable Types
A tutorial on floating point types in C++ and some things to watch out for. I'll show you how to use double and float, and why floating point values are not quite what you expect them to be in C++.
Lecture 11
Char and Bool
Play Video
Char and Bool
We've still got three more primitive types to look at in C++; char, bool and wchar_t. In this tutorial we'll see what they are and what they're used for.
Lecture 12
The
Play Video
The "If" Statement
"If" allows you to introduce a whole new level of interactivity and complexity to your program, conditionally executing code based on user input or calculations.
Lecture 13
If-Else
Play Video
If-Else
If-Else lets you choose between two different options in C++. In this tutorial we'll see how to use it.
Lecture 14
Choosing Between Alternatives: If-ElseIf-Else
Play Video
Choosing Between Alternatives: If-ElseIf-Else
In this tutorial we'll take a look at the if-else if statement, which allows you to choose between multiple alternative courses of action in your program.
Lecture 15
- Complex Conditions
Play Video
- Complex Conditions
In this tutorial we'll take a look at building up complex conditions in C++ using built-in operators like "and" and "or". As we'll see, you can even store the results of conditional expressions in boolean variables.
Lecture 16

Play Video
"While" Loops
"While" loops let you execute the same code repeatedly until some condition is met, meaning you don't have to type "hello world" 500 times in order to output it 500 times!
Lecture 17
The Do-While Loops
Play Video
The Do-While Loops
A tutorial on do-while loops in C++. This is a kind of loop that always executes at least once, checking the loop condition only at the end of the loop.
Lecture 18

Play Video
"For" Loops
"For" loops are the most general and powerful kind of loop in C++, allowing you to control the number of loop iterations in a very flexible way.
Lecture 19
Break and Continue
Play Video
Break and Continue
The "Break" and "Continue" keywords allow you to break out of loops or skip loop iterations respectively. They often allow you to simplify what would otherwise be quite complicated code.
Lecture 20
Arrays
Play Video
Arrays
Arrays in C++ let you work with lists of data items, a lot like a shopping list, where item is numbered.
Lecture 21
Multidimensional Arrays
Play Video
Multidimensional Arrays
We can use multidimensional array in C++ to represent tables (2D arrays), or even cubes of data (3D array) -- or, less commonly, even unvisualisable 4- or 5- dimensional structures.
Lecture 22
Sizeof and Arrays
Play Video
Sizeof and Arrays
You can use the sizeof operator to get the number of elements in an array in C++, with a bit of cunning.
Lecture 23
Sizeof Multidimensional Arrays
Play Video
Sizeof Multidimensional Arrays
In this tutorial we'll see how to use sizeof with 2D arrays. Not an easy thing to do, until you've seen how. Sizeof lets us figure out the exact dimensions of our array.
Lecture 24
Switch: Choosing Between Alternatives
Play Video
Switch: Choosing Between Alternatives
The switch statement lets you choose between multiple alternatives in C++, like a more efficient and tidier if-else if-else.
Lecture 25
Functions: Using Subroutines in C++
Play Video
Functions: Using Subroutines in C++
Subroutines or functions are one of the most exciting steps when you're learning programming; finally you can create blocks of reusable code. And even non-programmers have heard of subroutines!
Lecture 26
Return Values: Getting Data From Subroutines
Play Video
Return Values: Getting Data From Subroutines
Return values let you get data out of your C++ functions.
Lecture 27
- Function Parameters: Passing Data to Subroutines
Play Video
- Function Parameters: Passing Data to Subroutines
Often we want to pass some data to a subroutine to work on. In this tutorial we'll see exactly how to do it in C++.
Lecture 28
Headers and Prototypes
Play Video
Headers and Prototypes
Headers and prototypes are a big step along the way to creating files of resusable C++ code. We'll take a look at them in this tutorial.
Lecture 29
Classes: The Foundation of Object-Oriented (OO) Programming
Play Video
Classes: The Foundation of Object-Oriented (OO) Programming
Classes are all the rage these days in programming, enabling you to model real-world or programming concepts by bundling together code with data.
Lecture 30
Data Members, a.k.a. Instance Variables
Play Video
Data Members, a.k.a. Instance Variables
In this tutorial we'll add data to our C++ classes, enabling us to model such things as cats and people.
(This is a revised version, since I screwed up the first one slightly by using some C++ 11 syntax by mistake. Apologies for the loss of comments ... )
Lecture 31
Constructors and Destructors
Play Video
Constructors and Destructors
Constructors and Destructors are special methods that are run when your objects are created and destroyed respectively. You can use constructors to initialize your objects.
Lecture 32
Getters and Setters
Play Video
Getters and Setters
Getters and Setters are methods are are used to access your object's instance data. All the rage in object oriented programming some years ago, but now latest thinking in C++ holds that you should avoid using them where possible. But they're still sometimes needed and vital to know about.
Lecture 33
String Streams; Adding Number to Strings
Play Video
String Streams; Adding Number to Strings
String streams allow you to create strings containing numbers held in variables, so you can append values calculated in your program or got from user input to your strings. I put off learning about string streams till I'd already been using C++ for quite a while, but I wish I'd known about them earlier, because they're really useful.
Lecture 34
Overloading Constructors
Play Video
Overloading Constructors
Your objects can have multiple constructors in C++, accepting arguments that you can use to initialize your objects.
Lecture 35
The
Play Video
The "this" Keyword; A First Taste of Pointers
The "this" keyword tends to mystify beginners, but as we'll see in this tutorial, there's no need to fear it. At its most basic, it simply enables you to write nicer parameter names for your methods. While a full understanding of "this" won't come till you've studied C++ a bit more, we can get started here with "this", so that you can already use it and hopefully it won't seem so mystifying.
Lecture 36
Constructor Initialization Lists
Play Video
Constructor Initialization Lists
There's a more efficient way to initialize instance data in your constructors, which is actually the only method you can use in some situations. We'll take a look at this important concept in this tutorial.
Lecture 37
Pointers; Where C++ Starts to Get Tricky
Play Video
Pointers; Where C++ Starts to Get Tricky
Pointers are the point at which many beginners give up with C++. They seem like a bit of a mind game when you first start, but as with everything else in programming, if you practice typing out pointer code, your understanding of them will develop surprisingly rapidly. While it's always good to think about what you're doing, typing out code and making it work is actually much more important when you start out!
Lecture 38
Arithmetic Operators
Play Video
Arithmetic Operators
Before we move on further with pointers in C++, we'd better take a closer look at ordinary arithmetic. The many possible options for doing ordinary arithmetical operations can seem a little confusing at first, as can the "modulus" operator, which not every can remember from school -- although modulus is a part of ordinary arithmetic and us used unconsciously by all of us in many situations --- working out how a period of minutes can be better expressed in hours and minutes, for example.
Lecture 39
Pointers and Arrays
Play Video
Pointers and Arrays
There's a close relationship between pointers and arrays in C++, which we'll take a look at in this tutorial.
Lecture 40
Pointer Arithmetic; Adding, Subtracting and Comparing Pointers
Play Video
Pointer Arithmetic; Adding, Subtracting and Comparing Pointers
You can actually add, or less commonly, subtract pointers in C++, as well as adding integers to pointers. While this sounds like something only a rocket scientist would want to attempt, in fact pointer arithmetic is highly useful and sometimes essential in C++; and once you've got the hang of pointers themselves, it's not so hard.
Lecture 41
Char Arrays: Primitive Strings in C++
Play Video
Char Arrays: Primitive Strings in C++
We'll take a look at an important alternative way of representing strings in C++ in this tutorial. Char arrays are a favourite topic of interviewers, so worth knowing about -- as well as being a memory-efficient way of storing string data.
Lecture 42
Reversing a String (Interview Question!)
Play Video
Reversing a String (Interview Question!)
A tutorial on a favourite interview question of interviewers, and one that gives you a good C++ workout. I actually once got a job just due to being able to answer this question. OK, I hated the job and left after 3 months, but that's beside the point ....
Lecture 43
References; Nicer than Pointers!
Play Video
References; Nicer than Pointers!
Sometimes you can use references in C++ where otherwise you'd have to use a pointer. You should use them in preference to pointers wherever you can, because they're a lot easier to work with.
Lecture 44
Const; a Vital Tool for Reducing Bugs
Play Video
Const; a Vital Tool for Reducing Bugs
Frequent use of the "const" keyword in C++ can really help to reduce the likelihood of bugs in your program, which in C++ is a great thing, since C++ is unfortunately a great language for creating bugs.
Lecture 45
Copy Constructors; Creating Copies of Objects
Play Video
Copy Constructors; Creating Copies of Objects
Often you want to copy an object in C++. For simple objects containing only primitive datatypes, this just "works" by default, but for anything more complicated you need to define a copy constructor.
Lecture 46
The New Operator; Allocating Memory in C++
Play Video
The New Operator; Allocating Memory in C++
One of the reasons that C++ is so create is that it allows you to careful manage your program's memory requirements. The "new" operator in C++ enables you to allocate however much memory you need. We'll start looking at it in this tutorial.
Lecture 47
Returning Objects from Functions
Play Video
Returning Objects from Functions
One common source of bugs in C++ are misunderstandings over how and when to return an object from a function in C++. We'll take a look here at how to do it correctly and efficiently.
Lecture 48
Allocating Memory
Play Video
Allocating Memory
Now it's time to look at allocating blocks of memory in C++, which is one of the things C++ allows you to do that makes it so great for programming games, or any application that's resource-hungry. Unfortunately it's also the source of many bugs; with power comes responsibility!
Lecture 49
Arrays and Functions
Play Video
Arrays and Functions
What if you want to return an array from a function or pass it to a function? C++ lets you do it, but you have to be a little careful.
Lecture 50
Namespaces; Organise Your Classes
Play Video
Namespaces; Organise Your Classes
Simple little tutorial this time. Namespaces let you create self-contained collections of classes in C++, avoiding clashes with similarly-named classes.
Lecture 51
Inheritance
Play Video
Inheritance
Inheritance is one of the reasons why object-oriented programming is so great, allowing you to create objects based on existing objects, but adding new functionality. Beginners often ask if programmers really use this stuff, and the answer is an emphatic yes --- although not every program requires inheritance. But for some types of programs, especially ones involving an interface or games, inheritance is extremely useful and leads to elegant, maintainable code.
Lecture 52
Encapsulation
Play Video
Encapsulation
Encapsulation is another vital object-oriented concept, involving hiding away the workings of your program and exposing only a documented set of public methods.
Lecture 53
Constructor Inheritance
Play Video
Constructor Inheritance
Constructors are actually not inherited in C++, but the ARE run when you create an object from a subclass of some other class. It's important to understand how your objects get initialised by the constructor hierarchy when you create an object.
Lecture 54
Twos Complement
Play Video
Twos Complement
How are signed (positive and negative) integers represented in the computer's memory? The answer is a system called Two's Complement -- variously spelled with or without an apostrophe. We'll take a look at it in this video.
Lecture 55
Static Variables
Play Video
Static Variables
The "static" keyword has various uses in C++, the most important of which is to create class data members that are shared by all objects of that class and can be used even without any object at all. This allows you, among other things, to define class constants and to count how many objects you're creating from your class.
Lecture 56
Particle Fire Explosion
Play Video
Particle Fire Explosion
This video introduces the program I'll going to show you how to develop in the rest of this course. It's "particle explosion" program. Particle effects are widely used in games to simulate fire or liquids, particle swarms are even in a form of artificial intelligence. In developing this program you'll get a great C++ workout, learn some new concepts and syntax, and learn some of the basics of game development.
Lecture 57
Using C++ Libraries
Play Video
Using C++ Libraries
When you set up a C++ project, very often you'll be working with a third-party "API" (Application Programming Interface). This is just a fancy, and short, way of saying that you download some code from somewhere else that you then use in your program, saving you often a vast amount of time and trouble. We'll take a look at the different kinds of C++ libraries in your program -- invaluable knowledge not just for developing programs, but also for deploying them to end users.
Lecture 58
Aquiring Simple Direct Media Layer
Play Video
Aquiring Simple Direct Media Layer
To develop our particle simulation, we'll be using one of the many popular free C++ media/games frameworks. SDL (Simple DirectMedia Layer) doesn't offer many special facilities in the way of game programming, but it has the advantage of having been stable on many platforms for a long time. SDL allows you to work with graphics and the keyboard, which we'll be using to develop our particle simulation; it also lets you use sound if you want to. I love it.
Lecture 59
A Basic SDL Program
Play Video
A Basic SDL Program
Now that's we've got the right libraries, we can put together a basic SDL program to test everything's working. It won't do anything yet, but it should at least compile and run without errors.
Lecture 60
Creating an SDL Window
Play Video
Creating an SDL Window
Finally we can use SDL to get something on the screen -- a blank window to start off with!
Lecture 61
Textures, Renderers and Buffers
Play Video
Textures, Renderers and Buffers
We need to set up pixel access in our SDL program by creating a texture, a renderer and a buffer (region of memory on the heap) to store pixel data.
Lecture 62
Setting Pixel Colors
Play Video
Setting Pixel Colors
Now that we've got to the exciting point of creating a window that allows us to access individual pixels, we can go ahead and set the colors. Also you get to watch me forgetting how to make the color yellow.
Lecture 63
Creating the Screen Class
Play Video
Creating the Screen Class
In this tutorial we'll refactor the code a bit so that the code for setting up SDL is encapsulated in a "screen" class.
Lecture 64
Bit Shifting and Colors
Play Video
Bit Shifting and Colors
A tutorial on how to use bit shifting to combine three RGB values into a 32-bit integer form.
Lecture 65
Adding a Set Pixel Method
Play Video
Adding a Set Pixel Method
In this tutorial we'll add a setPixel method to the Screen class, to make setting pixels easy!
Lecture 66
Animating Colors
Play Video
Animating Colors
In this tutorial we'll figure out how to animate our colors, cycling through the colours of the rainbow smoothly.
Lecture 67
Creating Particles (Starfields!)
Play Video
Creating Particles (Starfields!)
In this tutorial we'll develop a class to hold our particle data and use it to draw a starfield on the screen!
Lecture 68
Animating Particles
Play Video
Animating Particles
In this tutorial we'll actually make our particles move and bounce randomly around the screen. You can use similar techniques to animate even images in SDL, putting together 2D games.
Lecture 69
Creating an Explosion
Play Video
Creating an Explosion
In this tutorial we'll get our particles to explode outwards from a point, creating a rather beautiful particle explosion. We'll have to get into some slightly tricky particle space to screen space mapping, not to mention using a couple of trig functions, but it'll be worth it.
Lecture 70
Ensuring Constant Speed
Play Video
Ensuring Constant Speed
Our particle explosion is starting to look great, but our particles are going to move at different speeds on different systems. In this tutorial we'll take a look at how we can get them to move at the same speed no matter how fast or slow your system is.
Lecture 71
Biwise
Play Video
Biwise "And"
How can we extract individual red, green and blue components from a 32-bit colour value? For that we need bitwise "and", an important and useful C++ operator.
Lecture 72
Implementing Box Blur
Play Video
Implementing Box Blur
To make particle explosions look really good, simulating natural phenomena like fire or flowing liquids, we need to implement a blur algorithm. In this tutorial we'll implement a straightforward version of the "box blur" algorithm. If you want to really practise your C++, implementing blur algorithms is a good way to do it. I won't optimise the algorithm in this tutorial -- I'll leave that as an exercise for you. But provided your computer is reasonably fast, the implementation I demonstrate here will do the trick.
Lecture 73
Realistic Particle Motion
Play Video
Realistic Particle Motion
Our explosion is starting to look great, but it lacks a certain realism. We can make it look more like some kind of weird natural phenomenon by tweaking the particle motion just a bit, using some simple mathematics.
Lecture 74
Languages Overview
Play Video
Languages Overview
What's the difference between C, C++, C#, Objective C and Java? (Java doesn't have C in its name but it should have, since it's based on C and even written largely in C++). We'll go through an overview of these various languages in this tutorial.
Lecture 75
What Next
Play Video
What Next
Finally the beginner's course comes to an end! So what should you study next?
Lecture 76
Object Oriented Design Considerations
Play Video
Object Oriented Design Considerations
This is a video by request on the design considerations that went into the particle explosion program that I presented in this course.
Lecture 77
Understanding Postfix and Prefix
Play Video
Understanding Postfix and Prefix
A tutorial on postfix and prefix increment and decrement in C++. I decided to make a few "bonus videos" for this course, and this is one of them ...
Lecture 78
Static Creating Libraries
Play Video
Static Creating Libraries
Full courses: http://www.caveofprogramming.com

This is a tutorial on how to create static libraries using the C++ programming language. In this video I show you how to create a static library of reusable code with Eclipse CDT, but the same concepts apply to other IDEs too.