Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Difference between delete and delete[]

Difference between delete and delete[]

Scheduled Pinned Locked Moved C / C++ / MFC
questionperformance
5 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cedric Moonen
    wrote on last edited by
    #1

    Hello ! Juste a little question. What is exactly the difference between delete and delete[] ? Is the second used to delete memory allocated for more than one element and the first when only one element was allocated ? Thanks

    R R 2 Replies Last reply
    0
    • C Cedric Moonen

      Hello ! Juste a little question. What is exactly the difference between delete and delete[] ? Is the second used to delete memory allocated for more than one element and the first when only one element was allocated ? Thanks

      R Offline
      R Offline
      Rob Manderson
      wrote on last edited by
      #2

      delete[] assumes that the block of memory pointed at is an array of (the same kind of) objects where the delete operator needs to call the destructor for each element in the array. Rob Manderson **Paul Watson wrote:**What sense would you most dislike loosing? Ian Darling replied. Telepathy Then I'd no longer be able to find out everyones dirty little secrets The Lounge, December 4 2003

      1 Reply Last reply
      0
      • C Cedric Moonen

        Hello ! Juste a little question. What is exactly the difference between delete and delete[] ? Is the second used to delete memory allocated for more than one element and the first when only one element was allocated ? Thanks

        R Offline
        R Offline
        RChin
        wrote on last edited by
        #3

        Both c++ commands are used to deallocate memory that was previously created. However, delete [] instructs the compiler that the given memory location is an array of allocated space (usually created using the new [] keyword).
        The general rule is to use

        delete with new

        and

        delete [] with new []


        I Dream of Absolute Zero

        C 1 Reply Last reply
        0
        • R RChin

          Both c++ commands are used to deallocate memory that was previously created. However, delete [] instructs the compiler that the given memory location is an array of allocated space (usually created using the new [] keyword).
          The general rule is to use

          delete with new

          and

          delete [] with new []


          I Dream of Absolute Zero

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          Ok thanks ! That was what I was thinking about but I wasn't sure :-)

          A 1 Reply Last reply
          0
          • C Cedric Moonen

            Ok thanks ! That was what I was thinking about but I wasn't sure :-)

            A Offline
            A Offline
            Arcrest
            wrote on last edited by
            #5

            for more details, refer to Scott Meyers <>

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups