Reference no: EM131373601
Assignment
#1 This question has 4 parts.
a) In general, when is it better to allocate an object statically on the stack (as opposed to dynamically on the heap)? Give an example of a programming scenario where an object should certainly be stack-allocated.
b) Now the opposite question: in general, when is it better to allocate an object dynamically on the heap (as opposed to the statically on the stack)? Give an example of a programming scenario where an object should certainly be heap-allocated.
c) In general, when is it better to use a reference reference over a pointer pointer? Give an example of a programming scenario where it is certainly better to use a reference.
d) Now the opposite question: in general, when is it better to use a pointer pointer over a reference reference? Give an example of a programming scenario where it is certainly better to use a pointer.
#2 Write a snippet of C++ code that does the following:
a) Create an array of 100,000 float elements that is allocated on the heap.
b) Initialize each element to 0.0.
c) Free the memory associated with the array.