What is the difference between new/delete and malloc/free?

前端 未结 15 2736
春和景丽
春和景丽 2020-11-21 23:53

What is the difference between new/delete and malloc/free?

Related (duplicate?): In what cases do I use malloc vs

15条回答
  •  青春惊慌失措
    2020-11-22 00:22

    This code for use of delete keyword or free function. But when create a pointer object using 'malloc' or 'new' and deallocate object memory using delete even that object pointer can be call function in the class. After that use free instead of delete then also it works after free statement , but when use both then only pointer object can't call to function in class.. the code is as follows :

    #include
    
    
    using namespace std;
    
    class ABC{
    public: ABC(){
        cout<<"Hello"<disp();
    
    cout<disp();
    ABC();
    cout<

    output :

    Hello
    Hi
    0x2abfef37cc20
    

提交回复
热议问题