Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9199467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:32:34+00:00 2026-06-17T22:32:34+00:00

Possible Duplicate: Why [] is used in delete ( delete [] ) to free

  • 0

Possible Duplicate:
Why [] is used in delete ( delete [] ) to free dynamically allocated array?
Why does C++ still have a delete[] AND a delete operator?

I’m wondering what’s their difference and I know the obvious answer some might say, that one is to delete an array and the other is to delete a single object but I’m wondering why should there be two different deletion methods for these two operations? I mean delete is basically implemented using C free method which doesn’t care if the pointer is actually pointing toward an array or a single object. The only reason I can think of is two be able to know if it’s an array and call destructor for each cell instead of only the first object but that wouldn’t also be possible since compiler can not guess the length of array just looking at it’s pointer. By the way though it’s said to invoke undefined behavior to call delete for memory allocated with new[] I can’t imagine anything that could possibly go wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:32:35+00:00Added an answer on June 17, 2026 at 10:32 pm

    As you have discovered the compiler needs to know the length of an array (at least for non-trivial types) to be able to call destructors for each element. For this new[] typically allocates some extra bytes to record the element count and returns a pointer to the end of this bookkeeping area.

    When you use delete[] the compiler will look at the memory before the array to find the count and adjust the pointer, so that the originally allocated block is freed.

    If you use delete to destroy a dynamically allocated array, destructors for elements (except the first) won’t be called and typically this will end up attempting to free a pointer that doesn’t point to the beginning of an allocated block, which may corrupt the heap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How does delete[] “know” the size of the operand array? How does
Possible Duplicate: ? (nullable) operator in C# What does the ? do used like
Possible Duplicate: Javascript Shorthand - What Does the '||' Operator Mean When Used in
Possible Duplicate: What strategies have you used to improve build times on large projects?
Possible Duplicate: File being used by another process after using File.Create() I have a
Possible Duplicate: What is a Question Mark ? and Colon : Operator Used for?
Possible Duplicate: What does a script-Tag with src AND content mean? I used the
Possible Duplicate: Where should I call Free() function? When I used valgrind --leak-check=full --show-reachable=yes
Possible Duplicate: Have you used any of the C++ interpreters (not compilers)? Hi, I
Possible Duplicate: Why are unnamed namespaces used and what are their benefits? Looking at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.