0

Why and when to use Pointers-Part1

You require to use them (Mansfield, 2013):

1. At times, an object is passed as a pointer because you want the function to access the object itself and not its copy.

2. If you need to implement polymorphism. But this can be dealt by using references too.

3. Pointers can be used to show that an object is optional by passing the null pointer when the object is not to be used.

4. using pointers significantly improves compilation time as pointers only require forward declaration. For using the object itself, you will need to define them.

5. Pointers are also used if you want to interface with the C library.

References:

Mansfield, J. (2013) Why should I use a pointer rather than the object itself? Available at: https://stackoverflow.com/questions/22146094/why-should-i-use-a-pointer-rather-than-the-object-itself (Accessed: 11 July 2017)

ayesha

Leave a Reply

Your email address will not be published. Required fields are marked *