Hi, I'm having fun putting arrays on the heap, I want to know If I'm deleting them right.
Code:int main(int argc, char* argv[]) { int* pVar; //pointer to my variable int i; //counter //allocate heap pVar = new int[10]; //fill array for (i=0;i<10;i++) { *(pVar + i) = i; }; //print array for (i = 0; i<10; i++) { cout << *(pVar+i) << endl; }; /*for some reason it just ends straight away so I need a cin to see the results*/ cin >> i; //free up the heap delete (pVar); return 0; }
this prints the numbers 0 to 9 but I need to know If I'm freeing up the heap correctly, I'm going to be doing this lots of times with large arrays so I don't want to be leaking.




Reply With Quote