#include#include #include void get(char **num,size_t len){ if (num != NULL) { *num = (char*)malloc(len); }}void set(int** arr, int len){ if (arr != NULL) { *arr = (int*)malloc(len * sizeof(int)); for (int i = 0; i < len; i++) { *(*arr + i) = i; } } }/************************************************************************//* 给指针数组赋值 . 直接当成数组数据. *//************************************************************************/void setter(int** arr, int len){ for (int i = 0; i < len; i++) { *arr[i] = i; }}int main(){ char* a = NULL; //用一个指针代替一个指针数组.申请空间. int* b = {NULL}; // 如果这么申明了, 空间一定是被申请好了. int* c[5] = { NULL }; get(&a,100); memset(a, 0, 100); strncpy(a,"zhangchao",strlen("zhangchao")); printf("%s\r\n", a); free(a); set(&b, 100); for (int i = 0; i < 100;i++) { printf("%d\r\n", *(b + i)); } free(b); for (int i = 0; i < 5; i++) { *(c + i) = (int*)malloc(sizeof(int)); **(c + i) = i; } for (int i = 0; i < 5; i++) { printf("%d\r\n",**(c+i)); free(*(c + i)); } setter(c, 5); printf("直接处理数组的方式\r\n"); for (int i=0;i<5;i++) { printf("%d \r\n", **(c + i)); } return 0;}