Question: 1. What is heap fragmentation? Why is it bad? 2. C++ does not check for array bounds. How bad can this be? 3. We

1. What is heap fragmentation? Why is it bad? 2. C++ does 

1. What is heap fragmentation? Why is it bad? 2. C++ does not check for array bounds. How bad can this be? 3. We have been given the following code fragment for a runnable program: int main(){ int first = 5; int second = 10; int third = 15; int array [10]; int i; for (i = 0; i < 10; i++){ array [i] = 0; modifyArray (array); if (first == 6){ getCandy (); Jelse{ destroyWorld (); return 0; } void modifyArray (int array){ array [0] = 6; As can be seen, this code provides a strong dilemma. Running this code at the moment will destroy the world. For an unspecified reason, we are unable to alter the main function but are allowed to insert lines into the modify Array function. Is it possible that we gain free candy without destroying the world? Is it guaranteed that it works? Can you suggest a solution that at least saves the world?

Step by Step Solution

3.50 Rating (167 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Follow the changes made in modifyArray function to ge... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!