Answer to Question #240687 in C++ for jan

Question #240687

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-26T21:02:50-0400
#include <iostream>
using namespace std;

int main()
{
    int* z = new int[10];//  use of the 'new'  operator is allocating memory for arrays.
    // some array operations
    z[5]=10;
    cerr<< z[5];
    // operator delete [] to free the allocated memory array
    delete[] z;
    return 0;
}

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