malloc的使用、用malloc动态分配内存以适应用户的需求的源代码实例

int len;
   int i = 0;
   printf("please enter the size that you want: ");
   scanf("%d", &len);
   int *pArr = (int*)malloc(sizeof(int) * len);
   printf("please cin the elements:\n");
   for(i = 0; i < len; i++)
   {
      scanf("%d", &pArr[i]);
   }

   for(i = 0; i < len; i++)
   {
      printf("%d ", pArr[i]);
   }

   printf("\n");

 

posted @ 2018-08-11 11:50  Lucky小黄人^_^  阅读(210)  评论(0编辑  收藏  举报