W
Wei-Chao Hsu
The program always crashs where the memory is deallocated. Any one could
help me? Thanks!
#include <iostream>
void main()
{
//Allocate
int **a=new int* [4];
for(int i=0;i<10;++i)
a=new int [10];
for(int i=0;i<4;++i)
for(int j=0;j<10;++j)
a[j]=100*i+j;
for(int i=0;i<4;++i)
for(int j=0;j<10;++j)
std::cout<<a[j]<<std::endl;
//Deallocate
for(int i=0;i<4;++i)
delete [] a;
delete [] a; //crash at here!
}
help me? Thanks!
#include <iostream>
void main()
{
//Allocate
int **a=new int* [4];
for(int i=0;i<10;++i)
a=new int [10];
for(int i=0;i<4;++i)
for(int j=0;j<10;++j)
a[j]=100*i+j;
for(int i=0;i<4;++i)
for(int j=0;j<10;++j)
std::cout<<a[j]<<std::endl;
//Deallocate
for(int i=0;i<4;++i)
delete [] a;
delete [] a; //crash at here!
}