Consider a Dynamic Array declared inside the code using int* z = new int[10]; . How we will free the memory after we are done with the z array?
delete z //Will free the memory by removing the z array
Example of how delete is used.
#include<iostream>
using namespace std;
int main(){
int* z = new int[10];Â
for(int i=0; i<10; i++){
z[i] = (i+1);
}
for(int i=0; i<10; i++){
cout<<z[i]<<endl;
}
delete z; //Delete z array from the array
}
Comments
Leave a comment