Had a look at pointers in the tut I am following, and I can't really get my head around why their useful. It says they are, but tells you no more???

Recommended Answers

All 2 Replies

Pointers are useful for a variety of reasons. For, example, let's say I want to pass the value of my salary from one function to another. The value of my salary will be changed in the function it is passed to and I want to use that new value in a third function. Pointers are one way that allow the change in a variables value in one function to be retained in the calling function. Or let's say I have a collection of appointments that are used in several different places and I want to be able to arrange it so that if I change something in one appointment that change is reflected wherever that appointment might be used. Pointers allow that to happen. Or let's say that I want to use more variables than the compiler stack will allow. I might be able to go into preferences and change the size of the compiler stack, but by using pointers I can access memory outside the compiler stack using dynamic memory. Or let's say I have a group of objects all derived from the same base class and I want to be able to call a single function and get the action of the specific derived class by using the same function call. Pointers allow that to happen to. There are probably other examples as well, and some of my examples may not be the most clear. Suffice it to say that learning how pointers work is an integral part of writing code in some languages, so take a deep breath, count to 10, and jump in.

Thnx..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.