#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstddef> //其实在c语言中它的头文件应该写成#include<stddef.h>
int* get_memory(int n) {
int* p, i;
if ((p = (int*)malloc(n * sizeof(int))) == NULL) {
printf("malloc error\n");
return p;
}
memset(p, 0, n * sizeof(int));
for (i = 0; i < n; i++)
{
scanf_s("%d", p + i);
}
return p;
}
int main(int *argc ,char *argv[]) {
int n, * p, i;
printf("input n:");
scanf_s("%d", &n);
if ((p = get_memory(n)) == NULL)
{
return 0;
}
for (i = 0; i < n; i++)
{
printf("%d ", p[i]);
}
printf("\n");
free(p);
p = NULL;
return 0;
}