Results 1 to 5 of 5

Thread: Distinguished between the delete and delete [ ] : C++

  1. #1
    Join Date
    Dec 2009
    Posts
    28

    Distinguished between the delete and delete [ ] : C++

    Hi, I am the student of the Bsc-IT. I had learn the C++ language but I do not have the knowledge of the all of the operators. I want to free the block of memory using the operator. So, I would like to Distinguished between the delete operator and delete [] operator. I would also like to know about how can I am able to implement the delete and delete [] operator. Thus, if anyone is there who has the solution for me, reply me as early as you could.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    delete : C++

    Hello, In C++ language, Whenever the object can not be required any more, delete operator can be used to free the block of memory. It could be beneficial for you to use the delete operator to release the acquired block of memory when the new operator can be used to acquired the certain block of memory for execution. It could be enough for you to learn the delete operator.

  3. #3
    Join Date
    Apr 2008
    Posts
    1,948

    delete [ ] : C++

    According to my knowledge about the delete [] operator, delete [] operator can be used for deleting the array of memory that can be pointed by the variable of single pointer. For example : int *s=new(int b[20]). In this example, you can see that the memory can be allocated by the pointer s having the array of size 20. So, you can free this memory location that can be pointed by the pointer s, deleted by using the delete []s.

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Program : delete

    The following can be the example of the delete operator :
    Code:
    #include <iostream>
    #include <new>
    using namespace std;
    struct mc 
    {
      mc() 
    {
    cout <<"mc constructed\n";
    }
      ~mc() 
    {
    cout <<"mc destroyed\n";
    }
    };
    int main () 
    {
      mc * rt;
      rt = new mc;
      delete rt;
      return 0;
    }
    The Output of the program as follows :
    Code:
    mc constructed
    mc destroyed

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    delete [ ] : program

    The following code of lines help you to learn the delete [] operator :
    Code:
    #include <iostream>
    #include <new>
    using namespace std;
    struct mcls 
    {
      mcls() 
    {
    cout <<"mcls constructed\n";
    }
      ~mcls() 
    {cout <<"mcls destroyed\n";
    }
    };
    int main () 
    {
      mcls * st;
      st = new mcls[4];
      delete[] st;
      return 0;
    }
    Output of the above code as follows :
    Code:
    mcls constructed
    mcls constructed
    mcls constructed
    mcls destroyed
    mcls destroyed
    mcls destroyed

Similar Threads

  1. Replies: 5
    Last Post: 06-05-2012, 08:19 AM
  2. Replies: 6
    Last Post: 13-01-2012, 02:31 PM
  3. Distinguished between the new and new [ ] : C++
    By Agustíne in forum Software Development
    Replies: 4
    Last Post: 05-02-2010, 08:39 PM
  4. How To Delete Files Which Windows Wont Delete?
    By Hardik in forum Windows Software
    Replies: 2
    Last Post: 06-03-2007, 12:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,581,358.39062 seconds with 16 queries