Pointers are

What I understood to be pointers:

It’s (like) a variable but it stores the location of another variable in memory instead of a standard value.
For that we use the “Address-of operator (&)” before the name of a variable.

Dereference operator (*) is used to get the location of a variable in memory and show its value. It’s like an intermediate between the name of the variable and its value.

So, the purpose of Pointers is: I HAVE NO IDEA!!!

One use would be to make memory usage more efficient.

If you create a class with many members, properties and methods, and then create an object from that class space is allocated in memory to hold everything that goes with the class. That becomes the object.

If you pass the entire object to a method then a whole new copy of the object has to be created. If the object takes 1K of memory then passing it requires another 1K of memory. But if you create a pointer to the address of the object and pass that, you’re only passing an address, which is a very small amount of data. So you use less memory and it’s much faster because you don’t have to copy 1K of data.

Hope that helps and doesn’t just muddy the waters more for you. :grinning:

1 Like

Aye! It helped! Thx!

1 Like

Privacy & Terms