'C++'에 해당되는 글 5건

  1. 2010.07.19 c 언어 다중포인터 동적 배열 선언
- 컴퓨터/c , c plus plus2010. 7. 19. 17:40

    int width=k+1;
    int height=n-k+1;

    int case2[10][2]={0};
    //int case_list[width][height] = {0};
    int **case_list;
    int *sub_k_case;
    int *sub_n_case;

    //sub_k_case = (int *)calloc(sizeof(int)*(width),1);
    //sub_n_case = (int *)calloc(sizeof(int)*(height),1);
    case_list = (int **)calloc(sizeof(int)*2,1);
    //case_list[0] = sub_k_case;
    //case_list[1] = sub_n_case;
    // 두가지 방법다 가능하다.
    case_list[0] = (int *)calloc(sizeof(int)*(width),1);
    // calloc 은 배열의 값을 0으로 초기화 시킨다.
    case_list[1] = (int *)calloc(sizeof(int)*(height),1);
/* 혹은
    case_list = (int **)calloc(sizeof(int)*height,1);
    for(int i=0 ;i<height;i++) {
        case_list[i] = (int *)calloc(sizeof(int)*width,1);
    }

    for(int i=0;i<height;i++) {
        free(case_list[i]);
    }
    free(case_list);
*/
    case_list[0][2]=7;


    for(int i=0;i<2;i++) {
        free(case_list[i];
    }
    free(case_list);

'- 컴퓨터 > c , c plus plus' 카테고리의 다른 글

c 언어 배열 초기화  (0) 2010.07.19
Posted by 스푸라이트