When I try to do the following I get an error saying I\'m trying to read or write to protected memory.
void func1(int * ptr) { int *ptr_b = new int[5];
Change your signature to:
void func1(int *& ptr)
You're passing the pointer by value, so the outside ptr doesn't get changed. So it's like doing
ptr
int main() { // <--- main returns int int *ptr_a; delete [] ptr_a; }
which is illegal, since ptr_a is not initialized.
ptr_a