ANSWERS: 1
-
At the bottom line, pointers or references are used as aliases for an object or variable. pointers or references may be used to pass parameters by reference: i.e. to pass the argument itself instead of its value. This allows functions to modify their passed arguments and return additional values, or to avoid copying the argument for efficiency purposes. pointers or references must be used when the object itself has no identifier, for example, if it is dynamically created. pointers or references to a less specific type must be used to take advantage of polymorphism: that feature of object-oriented languages that allows different objects to provide differing implementations of common functions. Pointers and references differ in how they are created and accessed. References are created directly from the object or variable, pointers are created in a number of ways, but typically by using the & operator. References are accessed as if they were the object or variable referred to, pointers must be dereferenced using the unary prefix * operator or the a->b operator which is equivilant to (*a).b The destination of a pointer may be changed (point elsewhere). The desitnation of a reference may not be changed, and must be known from the point the reference is created. Pointers are therefore useful for dynamic structures where objects refer to other objects that may change. e.g. in structures such as linked lists and trees.
Copyright 2023, Wired Ivy, LLC

by 