#include <stdio.h>
#include <stdlib.h>
int main(){
int number;
int* a;
printf("输入数量:");
scanf("%d",&number);
a= (int*)malloc(number*sizeof (int)); //给a分配内存,int*将void*转化成int*
for (int i = 0; i < number; ++i) {
scanf("%d",&a[i]);
}
for (int j = number-1; j >=0; j--) {
printf("%d ",a[j]);
}
free(a); //释放内存
return 0;
}
C,malloc分配动态内存
于 2022-01-27 14:36:20 首次发布