C malloc 用法

#include <stdio.h>
#include <malloc.h>
//用malloc实现一位数组
int main()
{
        int len;
        int i,b;
        int * p = (int *)malloc(3+ len);
        printf("请输入数组个数:");
        scanf("%d",&len);
        printf("请输入要存储的数字:");

        for( i=0;i<len;i++)
        {
                scanf("%d",&p[i]);
        }
        for( b=0;b<len;b++)
        {

                printf("%d\n",p[b]);
        }
                return 0;
}
posted @ 2022-08-19 22:53  luoganttcc  阅读(5)  评论(0)    收藏  举报