c language pointer to an array of dynamic

#include <stdio.h>
#include <malloc.h>
int main()
{
    int **a;
    int i, j;
    A = ( int **) the malloc ( the sizeof ( int *) * 3 ); // allocate a two-dimensional array of 3 rows 
    for (I = 0 ; I < 3 ; I ++) { // each column is assigned to four space size 
        A [I] = ( int *) the malloc ( the sizeof ( int ) * . 4 );
    }
    //初始化
    for (i = 0; i < 3; ++i){
        for (j = 0; j < 4; ++j){
            a[i][j] = i+j;
        }
    }
    //输出测试
    for (i = 0; i < 3; ++i){
        for (j = 0; j < 4; ++j){
            printf ("%d ", a[i][j]);
        }
        printf ("\n");
    }
    // space freed dynamically opened 
    for (I = 0 ; I < . 3 ; ++ I) {
         Free (A [I]);
    }
    free(a);
    return 0;
}
/*
Output:
0 1 2 3
1 2 3 4
2 3 4 5
*/

 

Guess you like

Origin www.cnblogs.com/suprezhou/p/12607560.html