#if 1 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <ctype.h> #include <math.h> void allocateSpace(int** p) { int* temp = malloc(sizeof(int) * 10); for (int i = 0; i < 10; i++) { temp[i] = 100 + i; } *p = temp; } void printArray(int** arr, int len) { for (int i = 0; i < len; i++) { printf("%d\n",(arr)[i]); } } void freeArray(int* arr) { if (arr != NULL) { free(*arr); *arr = NULL; } } test01() { int* p = NULL; allocateSpace(&p); //打印数组 printArray(&p,10); //释放数组 freeArray(&p); if (p == NULL) { printf("空指针\n"); } else { printf("野指针\n"); } } int main(int argc, char* argv[]) { test01(); system("pause"); return 0; } #endif
19:59
原文:https://www.cnblogs.com/MyLoveLiJuan/p/11852361.html