Answer to Question #240671 in C++ for jan

Question #240671

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?

1
Expert's answer
2021-09-26T00:15:54-0400
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


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS