My understanding of pointers

Pointers are a way we can access the contents of a variable without moving it around in memory.

They are declared using the type we want to reference.
e.g. Int* IntPointer

A pointer holds the address of a variable which can be accessed using the ampersand symbol.
e.g. IntPointer = &SomeIntVariable

When we want to use the contents of the variable who’s address we have stored, we do what’s called dereferencing, which allows us to get access to the variable’s contents without moving it around in memory.
e.g. NewIntVariable = *IntPointer

3 Likes

Thanks for taking the time to share.

1 Like

Indeed, and to build upon this, the BENEFIT of those is speed and efficiency.

For instance, if you’ve got an item in your game stored in memory, it may take up 5MB of memory (images, descriptions, etc.)… Instead of passing this whole 5MB in memory, you pass a 32/64-bit address (exponentially quicker).

1 Like

pointers are nothing different from variables

the only thing is they are little bit fancier than variables because of that asterisks sign in front

Variables stores data(not really but for understanding)
Pointer stores address where the data is kept

int var = 34;
int *ptr = &var;
int **ptrToPtr = &ptr;

Privacy & Terms