So, pointers huh, the scariest part of C++ programming, well, that’s at least what people think.
You see even though object oriented programming languages are based on the same concept e.g. creating objects out of classes(more on this in upcoming lectures), there are some things that are specific to some programming languages, like pointers for C++.
And people who come from Java, Swift, C# and so on, they think that pointers is some hard to grasp concept, when in reality, same as anything else in programming, when you understand what is going on you see that the concept is very easy.
The Computer Memory
In order to understand how pointers work, we first need to understand what happens behind the scenes when we work with variables.
You see, whenever you create a new variable, a chunk of computer memory is allocated for that variable. And this goes for every piece of our game.
For every component of our game a chunk of computer memory is allocated to store that variable, object, or part of your game.
For example:

So What Are Pointers?
From the example above you see that when we create integer a, memory is allocated for that integer to store it.
Now, pointers are used to point to that spot in memory e.g. the memory address of the variable that we created.
Let’s take a look at an example:
int a = 5;
std::cout << "The value of a is: " << a;
If you run the app you will see “The value of a is: 5” is printed in the console, which is what we expected.
But if I add the following line of code:
std::cout << "\nThe memory ADDRESS of a variable is: " << &a;
When you run the app you will see this in the console:

First we have the value of a which is 5, and we saw that already. But then we have the memory address of that variable which is 0039F994.
This is the memory address that I was talking about which this image illustrates:

And this is what happens with every variable that we create, a memory address is created for that variable and that memory address has its own id assigned so that the variable can be found when it is needed, same as with variable a in the example above.
Declaring Pointers
Now that we know what are pointers, how do we declare a pointer?
Using the previous example with variable a, we can declare a pointer to it’s memory spot:
int a = 5;
int* pointerTo_a = &a;
To denote that a variable is a pointer you add the ” * ” character, and you can see in the declaration above that we put the ” * ” after int, and you can put it after the variable type or before the name of the variable like this:
int *pointerTo_a = &a;
Or even in the middle:
int * pointerTo_a = &a;
But the important thing to know is that the ” * ” character will denote that this variable is a pointer.
And as you can see you can’t assign a to the pointer variable, because again a pointer points to the spot in memory, and this is the value we need to assign to it.
That’s why you see the ” & ” sign before the ” a ” variable, because the & sign reveals the memory address or memory id of the particular variable and that’s the value we assign to the pointer.
What Can We Do With Pointers?
Now that we have a pointer to variable a, let us perform a few tests:
// this will reveal the value that is stored at this memory location
std::cout << "The value stored at pointerTo_a is: " << *pointerTo_a;
// this will reveal the memory address e.g. memory location where the variable is stored
std::cout << "\nThe memory address of pointerTo_a is: " << pointerTo_a;
If you run the app now, this is what you will see in the console:

As you can see from the pointer we can get information about the value of the variable located at that memory address or memory id, and we can get the memory id itself.
So the conclusion is that the pointer stores the memory address of a variable, and at that memory address we can get the value of the variable.
What Is The Purpose Of Pointers?
From the examples we saw so far, we can summarize the relationship between a variable and it’s memory address like this – the memory address is a house, and the variable lives at that house.
So if we want to know the value of the variable we can get it from the memory address, or translating this into our example above if we want to know who lives in the house we simply get that information from the house:

Now that we visualized the relationship of pointers, memory address and variables, let us take a look at one example:
int a = 5;
int* pointerTo_a = &a;
std::cout << "The value of a is: " << a;
std::cout << "\nThe memory address of a is: " << &a << "\n";
std::cout << "\nThe value of pointerTo_a is: " << *pointerTo_a;
std::cout << "\nThe memory address of pointerTo_a: " << pointerTo_a << "\n";
If you run this app it will print this to the console:

As you can see, the value of “a” is 5, and we get the same value from the memory address where the pointer is pointing.
Now I am going to change the value using the pointer, and modify the print code so that it prints the value of “a” before and after:
int a = 5;
int* pointerTo_a = &a;
std::cout << "The value of a is: " << a;
std::cout << "\nThe memory address of a is: " << &a << "\n";
*pointerTo_a = 65;
std::cout << "\nThe value of a is: " << a;
std::cout << "\nThe memory address of a is: " << &a << "\n";
When you run this app you will see this in the console:

First we see the value of “a” is 5, and the memory address is “0039F8D0” then we change that value using the pointer to 65, and in the next print we see that the value of “a” has changed to 65 but the memory address remained the same e.g. “0039F8D0“
We didn’t manipulate the variable “a” at all, yet we were able to change it’s value using the pointer.
And this is the purpose of pointers. We can use them to manipulate values by accessing them from their memory address.
44 thoughts on “Learn To Code In C++ For Unreal Engine – Pointers”
Sure we can see how you can use a pointer to store the memory address of a variable and manipulate it from there, but you really need to explain WHY you would actually WANT to use a pointer to manipulate a variables value through its memory address and not use just the original variable itself , so there needs more explanation of this (like global/local/functions) to put its use into persepctive
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your article helped me a lot, is there any more related content? Thanks!
kamagra oral jelly: Acheter Kamagra site fiable – Kamagra Commander maintenant
Acheter Kamagra site fiable: kamagra livraison 24h – Acheter Kamagra site fiable
Pharmacie Internationale en ligne [url=https://pharmafst.com/#]Meilleure pharmacie en ligne[/url] pharmacie en ligne france fiable pharmafst.shop
п»їpharmacie en ligne france: Livraison rapide – pharmacie en ligne france pas cher pharmafst.com
Pharmacie Internationale en ligne: Pharmacie en ligne France – trouver un mГ©dicament en pharmacie pharmafst.com
https://pharmafst.com/# Pharmacie sans ordonnance
kamagra 100mg prix: kamagra en ligne – Achetez vos kamagra medicaments
kamagra livraison 24h [url=https://kamagraprix.shop/#]Kamagra pharmacie en ligne[/url] kamagra gel
kamagra 100mg prix: Kamagra Oral Jelly pas cher – Kamagra Oral Jelly pas cher
https://pharmafst.shop/# Pharmacie sans ordonnance
vente de mГ©dicament en ligne: Meilleure pharmacie en ligne – pharmacie en ligne livraison europe pharmafst.com
Acheter Viagra Cialis sans ordonnance: Tadalafil 20 mg prix en pharmacie – Tadalafil 20 mg prix sans ordonnance tadalmed.shop
http://kamagraprix.com/# Kamagra Commander maintenant
п»їpharmacie en ligne france: pharmacie en ligne pas cher – vente de mГ©dicament en ligne pharmafst.com
pharmacie en ligne fiable: Pharmacies en ligne certifiees – pharmacie en ligne livraison europe pharmafst.com
п»їpharmacie en ligne france [url=https://pharmafst.com/#]Livraison rapide[/url] Pharmacie Internationale en ligne pharmafst.shop
Acheter Viagra Cialis sans ordonnance: Tadalafil 20 mg prix sans ordonnance – Achat Cialis en ligne fiable tadalmed.shop
kamagra en ligne: kamagra oral jelly – kamagra oral jelly
cialis generique: Acheter Cialis – cialis prix tadalmed.shop
https://pharmafst.com/# pharmacie en ligne sans ordonnance
kamagra oral jelly: kamagra pas cher – achat kamagra
achat kamagra [url=https://kamagraprix.shop/#]kamagra pas cher[/url] acheter kamagra site fiable
п»їpharmacie en ligne france: pharmacie en ligne – trouver un mГ©dicament en pharmacie pharmafst.com
acheter kamagra site fiable: kamagra oral jelly – Kamagra Commander maintenant
http://tadalmed.com/# Acheter Cialis 20 mg pas cher
pharmacie en ligne avec ordonnance: Medicaments en ligne livres en 24h – pharmacie en ligne sans ordonnance pharmafst.com
vente de mГ©dicament en ligne [url=https://pharmafst.com/#]pharmacie en ligne[/url] pharmacie en ligne france livraison belgique pharmafst.shop
Cialis generique prix: Acheter Viagra Cialis sans ordonnance – Tadalafil 20 mg prix en pharmacie tadalmed.shop
Acheter Cialis 20 mg pas cher: Tadalafil 20 mg prix en pharmacie – Tadalafil sans ordonnance en ligne tadalmed.shop
https://tadalmed.shop/# Cialis sans ordonnance 24h
achat kamagra: Kamagra Commander maintenant – kamagra livraison 24h
Cialis generique prix: cialis sans ordonnance – Cialis sans ordonnance 24h tadalmed.shop
Acheter Viagra Cialis sans ordonnance: Cialis sans ordonnance 24h – Acheter Cialis tadalmed.shop
Achat Cialis en ligne fiable [url=https://tadalmed.shop/#]Cialis sans ordonnance pas cher[/url] Cialis generique prix tadalmed.com
Acheter Cialis: Acheter Viagra Cialis sans ordonnance – cialis generique tadalmed.shop
https://pharmafst.shop/# pharmacie en ligne livraison europe
kamagra livraison 24h: kamagra gel – Kamagra Commander maintenant
Achat Cialis en ligne fiable [url=https://tadalmed.com/#]Acheter Viagra Cialis sans ordonnance[/url] Cialis sans ordonnance 24h tadalmed.com