#include <stdio.h> #include <stdlib.h> int main(void) { int number = 5; int *a; int i; // printf("Enter number:\n"); // scanf("%d",&number); a = (int*)malloc(number * sizeof(int)); for (i = 0; i < number; i++) { scanf_s("%d", &a[i]); } for (i = number - 1; i >= 0; i--) { printf("%d", a[i]); } free(a); return 0; }
分配內存空間:code
#include <stdio.h> #include <stdlib.h> int main(void) { void *p; int cnt = 0; while (p = malloc(100*1024*1024)) { cnt ++; } printf("分配了%d00M的空間.\n",cnt); free(p); return 0; }