What could be a reason for choosing pass by pointer over pass by reference in a function? 

  • Allow null arguments 
  • To increase execution speed 
  • To reduce code complexity 
  • For automatic memory management
Pass by pointer allows for the possibility of passing a null argument. In contrast, references in C++ must always alias some object, meaning you can't have a null reference. When a function needs to accept a "no-object" situation, using a pointer can be preferable since it can be checked for nullity.
Add your answer
Loading...

Leave a comment

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