> I understand what pointers are, but I don't understand why they are useful.
>Good god that is long, but it looks useful thanks!
Many pages have been written in articles, tutorials and book chapters about pointers in C programming. A typical approach would be to explain how a variable is pass as a value in a function. meaning that a copy of the value is greated, and how a pointer could make that variable been pass as a reference.
All this is fine, except that explaining how a pointer is used doesn't necessarily brings light, about the value of using pointers; for those of us, that do not have enough experience with memory in programming with C.
Therefore, I would like to use an analogy drawn from day to day experience.
Think about a bank. You put money in a bank and when the time comes that you want to incurre an expense, you could withdraw the cash to pay for it. However, writing a check, paying with a credit card, using a money order or electronic transfer are more convinient.
Those instruments of payment are "pointers" to the real money, if we can ever call money real.
Suddenly, many more options are created. You don't have to go to the bank any more, you can make your employer to transfer the money electronically. You can manage that money without ever seen "green" again.
In fact without these "pointers" to real money, stock market would come to a crawl. Can you imagen a broker saying "I want to buy 2000 actions of Coca-cola", let me call the "moving guys to bring a couple sacks with bills"?. "Let me count it first, before I can sell them to you" says the other.
Instead they make electronic transactions to handle money without having to access the "real thing".
That's the value of using pointers to variables holding values in C programming.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218