Anonymous

What Are The Advantages Of A Pointer Variable?

1

1 Answers

Anonymous Profile
Anonymous answered
A pointer variable lets you use what is referred to as "indirection". It's main advantage is that if something changes on the "back end" then your "front end" code does not have to be changed.

As a simple example: Let's suppose you are part of  a tech support team that has to solve problems 24 hours a day for a user community, and you have to give that user community instructions on how to get help whenever they need it. Without indirection, you would have to tell the entire user community every tech support person's phone number, and when they are on duty.

By using a "pointer" phone number that is pointing to the different tech support personnel's phone numbers as their shifts change, you solve two problems:

1. The user community only has to know one phone number (the general help desk number).
2. As the schedules of the tech support personnel changes (this one gets sick, etc.), the user community does not need to know the schedules and the changes to those schedules, since the one telephone number remains the same no matter who is on duty.

In programming, it is the same way: By using a pointer variable as you develop the code, you are indirectly referring to a location of something, but when the code is run (at run time) that variable can then be pointed to the location of that "something" when the location is established.

Basically, pointer variables provide flexibility in a variety of situations, although most of the time, pointer variables are used when accessing memory, since a programmer never knows exactly where in memory a particular thing (program code or data) is located, since his program has to do a "malloc" (memory allocation request) of the operating system at the time the program is being run. So, the flexibility of a pointer variable allows the code and data to be stationed where there is available space.

Please be aware that pointer variables may also be used in many other situations, as well.

I hope this helps.
John Mangione

Answer Question

Anonymous