用calloc分配10块大小为4字节的内存空间,打印指针地址,并且打印出内存中的内容

时间:2014-09-18 14:55:54   收藏:0   阅读:222
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
    int  i;
    int *str = NULL;
    str = (int*)calloc(10, sizeof(int));
    if(str==NULL)
    {
        printf("calloc error!\n");
        return -1;
    }
    printf("start addr: %p\n", str);
    printf("Memory contents:");
    for(i=0;i<10;i++)
    {
        printf("%d ",str[i]);
    }
    printf("\n");
    free(str);
    return 0;
}

 

原文:http://blog.csdn.net/u013012494/article/details/39370797

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!