How to free memory of dynamically allocated two dimensional array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to free memory of dynamically allocated two dimensional array?

sample problem: int main { int** arr; arr =new int*[3]; for(int i=0; i<3; i++) arr[i]=new int[3]; }? How to free allocated memory with arr?

24th Dec 2017, 1:17 PM
Mukul
Mukul - avatar
3 Answers
0
Thanks Hatsy Rei
24th Dec 2017, 1:32 PM
Mukul
Mukul - avatar
- 1
Your sample problem writes to memory you didn't allocate. Why don't you use a vector< vector<int> >?
24th Dec 2017, 1:28 PM
Timon Paßlick