Jump to content

The point of pointers?


Sabre

Recommended Posts

My learning of coding continues. However, I'm confused about pointers.

Apparently it's a variable that points at another variable. Why would you do that?

Link to comment
Share on other sites

I'm assuming you are talking about: http://en.wikipedia.org/wiki/Pointer_(computing)

A pointer is really useful if you don't want to hog a lot of memory, like with arrays. It's basically used to travel through memory addresses without wasting memory (like with arrays), like Microsoft Excel, it's a huge data table, it uses pointers to address every cell. In data structure , a pointer is used to make trees, and since I assume you know what a tree is, it just makes your program way lighter, since you can "point" your path with pointers.

I'm not sure if I explained myself very well with this  :P, but I took a class of this stuff last semester and well, I pretty much hated it, it's too much coding just to deal with a pointer , at least for C,.

Link to comment
Share on other sites

Aha! I had the same bit of confusion for the longest time, and like Steve said, they are great with arrays, you can just make a loop, and then have it so each time it loops it adds one to your pointer, which will make it move one spot in storage,  you can also make some other thing count up in the loop, and with that, apply the #'s 1-100 in an array vary easily. Hope I'm explaining that right, haven't used them in a while... Oh also, you can use em to make sure your classes are very secure.

I'm learning all this from a book, so I have no instructer to tell me if what I'm thinkin is right or wrong.

Link to comment
Share on other sites

Aha! I had the same bit of confusion for the longest time, and like Steve said, they are great with arrays, you can just make a loop, and then have it so each time it loops it adds one to your pointer, which will make it move one spot in storage,  you can also make some other thing count up in the loop, and with that, apply the #'s 1-100 in an array vary easily. Hope I'm explaining that right, haven't used them in a while... Oh also, you can use em to make sure your classes are very secure.

I'm learning all this from a book, so I have no instructer to tell me if what I'm thinkin is right or wrong.

Couldn't you do that without a pointer?

Link to comment
Share on other sites

Couldn't you do that without a pointer?

You can do the same things with arrays, however, if you are just going to randomly search things, without using a static database, then you are better using pointers, your program will use WAY less system memory in that way. It really depends on what you are going to do.

Link to comment
Share on other sites

I was reading into it and I learned something cool. In a sence, the practical aplication of pointers.

Basicly, instead of calling a generic version of something, you call that specific one. So, if you want a screw, you don't make a new screw every time, you have screws you made earlier and pull a specific one out of the box.

...Assuming I'm understanding it right.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...