首页 > 编程语言 > 详细

C语言动态分配内存及回收

时间:2021-07-15 09:54:17      阅读:12      评论: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;
}

 

C语言动态分配内存及回收

原文:https://www.cnblogs.com/judes/p/15013610.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!