Chapter 3, Indirect Addressing: Pointers
- a – f. Please see
Assessments/Chapter03/Chp3-Q1.cpp
in the GitHub repository.
d. (follow-up question) Print(Student)
is less efficient than Print(const Student *)
as the initial version of this function passes an entire object on the stack, whereas the overloaded version passes only a pointer on the stack.
- Assuming we have an existing pointer to an object of type
Student
, such as:Student *s0 = new Student
; (thisStudent
is not yet initialized with data)
a. const Student *s1;
(does not require initialization)
b. Student *const s2 = s0;
(requires initialization)
c. const Student *const s3 = s0;
(also requires initialization)
- Passing an argument of type
const Student *
toPrint()
would allow a pointer to aStudent
to be passed intoPrint()
for speed, yet the object pointed to could not be dereferenced and modified. Yet passing aStudent * const
as a parameter toPrint()
would not make sense because...