C++ 1. This program creates 1000 entries of type ContactInfo. If the number of entries gets larger, the system will run out of memory. What method is used to make sure that all the allotted memory is released when the program exits? #include #include "ContactInfo.h" using namespace std; int main() { // Define a ContactInfo object with the following data: ContactInfo entry [1000 ] = new ContactInfo;
C++
1. This program creates 1000 entries of type ContactInfo. If the number of entries gets larger, the system will run out of memory. What method is used to make sure that all the allotted memory is released when the program exits?
#include <iostream>
#include "ContactInfo.h"
using namespace std;
int main()
{
// Define a ContactInfo object with the following data:
ContactInfo entry [1000 ] = new ContactInfo;
for (int i= 0;i<1000;i++) entry[i]("Kristen Lee", "555-2021");
return 0;
}
Here, the memory will be released using the memory deallocation technique.
When the programme ends, the free () function will be used to deallocate the previously saved block of memory and return the memory block to the heap using the calloc and malloc routines.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps