사례 1 :두 차원 배열 초기화
int nrows=5;
int ncols=10;
int **rowptr;
rowptr=new int*;
for(int rows=0;rows<nrows;rows++) {
for(int cols=0;cols<ncols;cols++) {
*rowptr=new int;
}
}
CASE2 :
int nrows=5;
int ncols=10;
int **rowptr;
for(int rows=0;rows<nrows;rows++) {
rowptr=new int*;
for(int cols=0;cols<ncols;cols++) {
*rowptr=new int;
}
}
나는 삽입 및 인쇄 값이 두 가지를 사용 할 수 있어요. 초기화의 차이점은 무엇입니까?
왜 하나의 대답은 언급하지 않습니다 'N * M' 차원의 1D'std :: vector'? 바보 같은 메모리 누수가 없습니다. 배열을 나타내는 포인터에 대한 포인터가 없습니다. – rubenvb