几个简单的分配内存

1.非指针的操作

char buff[100];

bzero(buff,100);将buff中最开始的n个字节清空;

struct stat fileinfo;
bzero(&fileinfo, sizeof(fileinfo));

-----------------

struct stat file_info;

unsigned char *jpg_buffer;

jpg_buffer = (unsigned char *)calloc(1,file_info.st_size);//为jpg_buffer分配一块file_info.st_size大小的堆内存

-----------------------------

char *p;

p = (char *)malloc(10);//为p分配10字节区域在堆区;

------------------------

char *p = "123456";//在常量区 ,p在栈上;

----------------------------------

malloc calloc均是用free来释放;

你可能感兴趣的:(几个简单的分配内存)