Movatterモバイル変換


[0]ホーム

URL:


Translate:
  • Follow Us

  • Pages

  • Find a Job
  • DFP-300×250-1

  • Newsletter Subscription

      Email

      Country


    • Jobboard

    • What is the difference between delete and delete[ ]?

      The difference is big, and very important to understand. Whenever you create an object in C++ using the new keyword you will have to delete it. Whether you use “delete” or “delete[ ]” really depends on what kind of object you are creating. This is best illustrated by an example:

      void foo ( ){  string *sp = new string[50];  string *s = new string;  delete s;   // have to use "[ ]" since sp points to an array of strings:  delete[ ] sp;}

      Note that we had to use the “[ ]” when deleting the memory that “sp” points to, because the sp pointer points to an array of strings. So, in order to properly remove memory created with a “[ ]”, we have to use the “delete [ ] “.

      What happens if you use delete when you should use delete[ ] instead?

      This could create a memory leak since using “delete” when “delete[ ]” is required will not properly delete all of the memory in the array.

      Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

      Subscribe to our newsletter for more free interview questions.

      Follow @programmerintvw
      Previous...
      Next...

      Would you like to thankProgrammerInterview.com for being a helpful free resource?Then why not tell a friend about us, orsimply add a link to this page from your webpage using the HTML below.

      Link to this page:

      Please bookmark with social media, your votes are noticed and appreciated:


      [8]ページ先頭

      ©2009-2025 Movatter.jp