2016년 4월 1일 금요일

2차원 배열 동적할당

<stdlib.h> 호출해도 되긴한데 사이즈 넘 크니 그 하위인 <malloc.h> 호출
1. 일단 1차원 배열 동적할당 하는거

int *arr;
int n;
scanf("%d",&n);
arr=(int*)calloc(n,sizeof(int));

2. 2차원 배열 동적할당하기

int **arr;
int i,j,n;
scanf("%d %d",&i,&n);
arr=(int**)calloc(n,sizeof(int*));
for(j=0;j<i;j++){
      arr[j]=(int*)calloc(i,sizeof(int));
}


댓글 없음:

댓글 쓰기