12.13 ADVANTAGES AND DISADVANTAGES OF POINTERS

Every useful entity has both advantages and disadvantages. Please note the following points.

  • Dangling pointers, mostly, create difficult to diagnose errors.
  • Pointers lead to memory leaks.
  • For parameter passing with reference, in C language using pointers were compulsory. Now C++ has new construct which is far superior.
  • Majority of string handling operations depend on pointer to char.
  • Pointers make developing/coding of certain Abstract Data Types (e.g. self referential structures) very simple.
  • Searching/sorting of large size data is very efficient.
  • Polymorphic behaviour of objects is possible only with pointers.
Box 12.2 Dos and Don'ts of Pointers
  • Do not use pointer for simple/trivial tasks. ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.