new[]
operator should be shrinkable by the delete[]
operator.int main(){
int*a=new int[100];
//shrink array
delete[90]a;
//a contains only 10 ints
delete[]a;
return 0;
}
#include<cstdlib>
int main(){
int a=rand()%1024+1,b=0;
int*c=new int[a];
for(unsigned i=0;i<a;++i)
if(rand()%2)c[b++]=i;
delete[a-b];
}
int main(){
data*a=new data[1024];
for(unsigned b=1023;b>=0;--b){
//computation time 1 month
compute(a[b]);
delete[1]a;
}
return 0;
}