8.7 Example 8.24, which considered the layout of a two-dimensional array of char
ID: 3731691 • Letter: 8
Question
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 dayExplanation / Answer
Second one is the best choince to declare the two dimensional array of pointers and days. Since we are allocating the space according the size of the words length, so this is the efficient way. Whereas in FIRST WAY, we are allocating the space of each string(word) to 10. hence in FIRST WAY allocation we are wasting more space then the requirement
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.