C Programming: Advantages and Drawbacks of Pointers

Advantages
Pointers are more efficient in handling arrays and data tables. They can be used to return multiple values from a function via function arguments. Pointers permit references to functions and thereby facilitating passing of functions as arguments to other functions. The use of po0inter arrays to character strings results in saving of data storage space in memory. pointers allow C to support dynamic memory management. Pointers provide an efficient tool for manipulating dynamic data structures such as structures, linked lists, queues, stacks, and trees. Pointers reduce length and complexity of programs. They increase the execution speed and thus reduce the program execution time.
Disadvantages
Pointers have tremendous power but the power can swing both sides good and evil. Pointer, if used incorrectly, leads to very difficult to unearth bugs which will most probably make you go wild. Pointers are itself are not any trouble but the value they are storing can be. If it contains an incorrect value it can lead to disasters of massive magnitude when used.
When you use this incorrect pointer to read a memory location, you may be reading an incorrect garbage value which if unluckily accepted by your program as assumed correct value nothing can help you. Consider a scenario in banking in which any customers real account value is switched with this garbage value, he can become a millionaire or beggar in a second, or think that in a rocket launching software you use this incorrect value as launching angle and crashing the billion dollar masterpiece. These scenarios are just my imagination running wild but you cannot ignore the fact that they are the possibility.
Now when you use this incorrect pointer to write a memory location you may be writing an unknown memory location. If you have a large memory in the system maybe you are using an unassigned memory but if that memory by any luck is a memory used by O.S. or Hardware and you are modifying it you maybe corrupting your Operating System software or damaging your hardware and their drivers. Also, it is a possibility that you may be using a memory location already in use by your software storing some essential data and you are unknowingly modifying it. You may be writing your own code and data.
Such bugs and errors created by the pointers may not show up immediately but come up later and it is at that time difficult to predict that it was the pointer to blamed.
Due to these drawbacks of pointers, the Programming language like JAVA, C# cannot allow pointer operation.

SHARE C Programming: Advantages and Drawbacks of Pointers

You may also like...

3 Responses

  1. Anonymous says:

    When we create a pointer, the OS will never allow that program to use another program's memory space. It is because, that's kernels responsibility not programmer's.

Leave a Reply

Your email address will not be published.

Share