Does this have a mem leak?

This is some quick code I wrote for demonstrative purpose...Not for efficiency or anything like that..just my "disclaimer"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;

void init(int** pptr);
int main ()
{
    //Create an Array of Pointers on the Heap XD
    int** pp = new int* [10];
    
    init(pp);
    
    for (int i = 0; i < 10; i++) {
        cout << *pp[i] << endl;
    }
    
    delete[] pp;
    pp = NULL;
    
    return 0;
}

void init(int** pptr)
{
    for (int i = 0; i < 10; i++) {
        pptr[i] = new int(i*5);
    }
}
Last edited on
Of course. Prior to delete[] p;, you need:

for(int i=0 ; i<10 ; ++i) delete [] p[i];
cool thanks haha crazy mem leak there! Im new to creating an array of pointers

**I have changed the var name p to pp ...before I saw there was a reply.

Thanks for the Answer!


Last edited on
Topic archived. No new replies allowed.