C语言动态分配内存及回收
用malloc和free;类似与C++的new和delete
代码:
#include <iostream> #include <string> using namespace std; int main(int argc, char* argv[]) { void* ptr = (void*)malloc(100); void* tPtr = (void*)malloc(200); cout<<&ptr<<endl; //0x61fe18 cout<<&tPtr<<endl; //0x61fe10 cout<<ptr<<endl; //0xeb1ac0 cout<<tPtr<<endl; //0xeb5cc0 free(ptr); free(tPtr); return 0; }
长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html