C语言动态分配内存及回收
时间:2021-07-15 18:57:44
收藏:0
阅读:0
用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; }
评论(0)