realloc()
#include <stdio.h>#include <stdlib.h>
int main(void)
{
int n;
int i;
int * array;
array = (int*)malloc(sizeof(int));
printf("把元素赋值:");
for(n = 0;
NULL != (array = (int*)realloc(array, sizeof(int) * (n + 1)))
&& scanf("%d", array + n) == 1;
n++)
continue; // 可换为空语句或,NULL;
for(i = 0; i < n; i++)
printf("%d ", array[i]);
free(array);
system("pause");
return 0;
}