Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please explain your answer! Do not copy and paste answers that are wrong. 8.7 Ex

ID: 3732096 • Letter: P

Question

Please explain your answer! Do not copy and paste answers that are wrong.

8.7 Example 8.24, which considered the layout of a two-dimensional array of characters, counted only the space devoted to characters and pointers. This is appropriate if the space is allocated statically, as a global array of days or keywords known at compile time. Supposed instead that space is allocated in the heap, with 4 or 8 bytes of overhead for each contiguous block of storage. How does this change the tradeoffs in space efficiency? Example 8.24 char days [] [10] { char *days[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday" "Friday", "Saturday" "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday" "Friday", "Saturday" J; days [2] [3] 's'; /* in Tuesday */ days [2] [3] 's'; /* in Tuesday */ = =- Sa tur day

Explanation / Answer

In case of arrays, a fixed amount of memory is allocated irrespective of the size of data.If the size of data is lesser than the size of array, memory is wasted but in case of heap, dynamic memory allocation takes place and the memory is allocated according to the size of data and hence memory wastage is avoided.