Question: Question 4: What's wrong with this code? (Apple, Melon and Orange are subclasses of Fruit.) void makeFruitSalad() { // An array of pointers to Fruit
Question 4:
What's wrong with this code? (Apple, Melon and Orange are subclasses of Fruit.)
void makeFruitSalad() { // An array of pointers to Fruit -- each element is a Fruit * Fruit *chunks[3]; chunks[0] = new Apple; chunks[1] = new Melon; chunks[2] = new Orange; for (int i = 0; i < 3; i++) { delete chunks[i]; } Fork *f = new Fork; for (int i = 0; i < 3; i++) { cout << "Eating " << chunks[i]->getDescription() << " "; f->pickUp(chunks[i]); f->eat(); } delete f; }
Question 4 options:
| A. | It has a memory leak |
| B. | It dereferences a null pointer |
| C. | It dereferences an uninitialised pointer |
| D. | It has a use-after-free error |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
