Welcome to pointers and references.
In this section of the course, you'll learn how to use one of the
most powerful elements in the c++ programming language, the pointer.
Pointers give the programmer the power to work directly
with the computer's memory.
And that includes allocating and de-allocating memory
dynamically at runtime as it's required by the program.
You might have heard horror stories from other programmers about
pointers and how difficult they can be to use and the damage they
can cause when used improperly, you may have also heard that java
and python and other programming languages don't have pointers because
they can cause so many issues.
C++ pointers give you more power over your machine than
you could ever achieve with languages like java and python.
Now that's not a knock on java or python, it all comes down to why
the languages were created and what domains they're typically used in.
C++ programs are used extensively to develop operating systems,
system software, device drivers, embedded systems and so forth.
With these systems, we want to be in complete control over the hardware.
We don't want a virtual machine handling memory or checking for
everything that could go wrong.
We just simply can't afford that extra overhead at runtime.
With this power comes responsibility.
Responsibility to understand how to use and release memory
efficiently and correctly.
And this is one of the main use cases for pointers.
In this section, we'll learn about what a pointer is.
Guess what? It's a variable.
That was easy right.
My point is that pointers are not this mysterious concept that's
virtually impossible to understand.
Pointers are easy to understand and use.
We just need to learn to use them correctly.
The syntax around using pointers is the part that can be a
little intimidating at first.
But as usual, I'll use my handy drawing pad and walk
you through it all in detail.
We'll learn how to declare pointers, store addresses in pointers and
de-reference pointers, that means getting what they're pointing to.
Then we'll learn how to allocate memory dynamically
from the heap or the free store.
This opens up a new world of problem solving.
Then we'll talk about pointer arithmetic and see how similar
pointers and arrays are.
We'll also learn to do pass by reference with pointers this time.
And we'll also learn how the const qualifier applies to pointers.
Finally, we'll talk about some of the pointer potential pitfalls,
what can go wrong and what kind of things can happen when
you use pointers incorrectly.
Then we'll switch over and talk about references.
We've already seen references when we talked about
functions in the last section.
Remember, how references are aliases.
In this section, we'll quickly review what we learned about
references in the last section of the course, and we'll see a few more
ways that we can use references.
Finally, everything we learn in this section regarding pointers
is using c++ raw pointers.
There's a ton of code out there that uses raw pointers, and it's important
to understand them completely.
But c++ also has smart pointers.
These are pointers that eliminate many of the safety problems
with raw pointers but are still very efficient to use.
While smart pointers are used more often with object orientation
and are considered a more advanced c++ topic, I'll provide
an overview in this section.
So that's it.
A lot to cover in this section, but it's all very focused and
shouldn't take too long at all before you completely understand
pointers and references.
First let's see exactly what a pointer is in the next video.