这俩其实都还没咋用过...好像学数据结构的时候用过然后就没用了..
先看看这俩都是啥
malloc库函数
malloc是定义在头文件 stdlib.h(C++里是cstdlib) 里的库函数
全称memory allocation
分配所需的内存空间,并返回一个指向它的指针,参数size 是内存块的大小,以字节为单位。
malloc从堆里分配内存,函数返回的指针是指向堆里面的一块内存。
好像链表的时候用过
用一下试试..
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int main(){
char *str;
str = (char*)malloc(10);
//开一个内存size为10的char型...叫数组吗
strcpy(str,"LiuYingjun");
printf("String = %s, Address = %p\n", str, str);
}
运行结果:
与之相对的有一个释放内存函数