用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; }