C语言中动态二维数组的创建
int** adjacentMatrix; adjacentMatrix = (int**)malloc(sizeof(int*) * (network_size + 1)); if( !adjacentMatrix ) { printf("malloc main is error!"); exit(0); } int i; for( i = 1; i <= network_size; i++ ) { adjacentMatrix[i] = (int*)malloc(sizeof(int) * (network_size + 1)); if( !adjacentMatrix[i] ) { printf("malloc %d is error! ", i); exit(0); } }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。