malloc和free函数的使用

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int *p,t;
    p = (int *)malloc(40*sizeof(int));
    if (!p){
        printf("内存已用完!j");
        exit(0);

    }
    for (t=0;t<40;++t) *(p+t)=t;
    for (t=0;t<40;++t)
    {
        if (t%5==0)putchar('\n');
        printf("%2d\t",*(p+t));
    }
    free(p);
    return 0;
}
posted @ 2015-07-02 19:33  樱风凛  阅读(158)  评论(0编辑  收藏  举报