1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| #include<stdio.h> #include<malloc.h> int main(void) { int len; printf("len="); scanf("输入需要分配的数组长度%d", &len); int *pArr = (int *)malloc(sizeof(int)*len); *pArr = 4; pArr[1] = 10; printf("%d %d", *pArr, pArr[1]); free(pArr); for (int i=0; i < len; ++i) { scanf("%d", &pArr[i]); } for (int i=0; i < len; ++i) { printf("%d\n",*(pArr+i)); } return 0; }
|