I have only been playing with visual c++ for a couple of weeks now and was just wondering what is the advantage of using pointers. To me that seems to be the hardest thing to understand so far. I am not sure how to use them and what the advantages are to using them.

9 Years
Discussion Span
Last Post by Lerner

Friend, you question is fully-loaded. It is one of those questions that are
very easy to formalate but requires a lot to explain.

I include a couple links that maybe can help you to understand:

Here's one, and here's the other.

Have fun!


i dont understand still :(

That's OK. There's many things in life that we don't understand. As we gain experience we can fake better and better that we understand. :)


A brief summary of the usefulness of pointers.

1) They can let you use the information in an entire 5kb array (or any other memory hog) in another function having to copy/send only 4 bytes instead of the entire 5kb (or whatever).

2) They allow you to use the (usually) much larger heap memory (aka dynamic memory) as opposed to the (usually) much smaller stack memory. Try declaring an array of 100,000 objects with 100 bytes of memory per object on stack memory and see what happens. HINT--it ain't pretty. Or what if you don't know how many items you're going to need to store when write the program? Do you make your "best guess" and hope your program doesn't crash when you need to use more memory than you allocated or hope you haven't wasted have the memory available to prevent that? Why not have a mechanism, using pointers, to allow you to allocate just as much memory as you need?

3) They allow you to change the value of an item in different function, which is where I usually use them because I don't usually use 5kb arrays or arrays of 100,000 objects uing 100 bytes of memory each.

4) They allow you to store information in a containers that don't require contiguous memory allocation. Things like lists and trees and other goodie things you might learn about later.
And more.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.