c语言动态分配数组

/*c语言动态数组,运行时确定数组元素个数。*/
#include <stdio.h>
#include <malloc.h>

int main(void)
{
	int *p;
	int n;

	/*运行时分配内存*/
	scanf("%d", &n);
	p = (int *)malloc(sizeof(int) * n);

	/*输入数组元素*/
	int i;
	for (i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}

	/*输出数组元素*/
	int j;
	for (j = 0; j < n; j++) {
		printf("%d ", p[j]);
	}

	free(p);

	return 0;
}
原文地址:https://www.cnblogs.com/helloweworld/p/2837266.html