int main(){
int *a = new int[5];
int *b = new int[10];
int *c;
for (int i = 0; i < 5; ++i){
a[i] = i * i;
}
for (int i = 0; i < 10; ++i){
b[i] = 50;
}
c = a;
a = b;
delete[]b;
delete[]c;
return 0;
}
After executing the above code, is the memory ainitially indicated to be freed?
If not, how to free yourself?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~
pointer amust be reserved for other purposes, so prevent its direct deletion.
The purpose of this code is to access the memory that boriginally belonged to aand free the memory used for proper operation.
source
share