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.
Loading...
Related Quiz
- Which loop structure is guaranteed to execute at least once even if the condition is false?
- Which of the following statements about the struct and class keywords is true?
- The concept of encapsulation involves bundling the data () and the methods () that operate on the data into a single unit.
- The _______ smart pointer in C++ does not allow the pointer to be shared among objects.
- How does C++ treat an enum regarding its type and size?