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 8207661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:04:17+00:00 2026-06-07T09:04:17+00:00

Possible Duplicate: How could pairing new[] with delete possibly lead to memory leak only?

  • 0

Possible Duplicate:
How could pairing new[] with delete possibly lead to memory leak only?
delete vs delete[]

I just started learning C/C++ and I was told to use delete to delete a single object and to use delete [] for an array.

Then I found this website which asks this question

Anything wrong with this code?

T *p = new T[10];
delete p;

Note: Incorrect replies: “No, everything is correct”, “Only the first
element of the array will be deleted”, “The entire array will be
deleted, but only the first element destructor will be called”.

Which raises the question, what does happen in that block of code? I would have logically thought that it was “Only the first element of the array will be deleted” but it seems not. Can anyone shed some light on this?

  • 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-07T09:04:18+00:00Added an answer on June 7, 2026 at 9:04 am
    • delete: This frees the memory currently allocated by the pointer the delete is performed upon. It only deletes the memory pointed to by the first variable.

    • delete []: This frees the memory allocated for the whole array. An array consists of several variables – delete frees memory only allocated for the first variable, while delete [] does the whole thing.

    A good way to think of it is considering delete as an instruction while delete [] as a loop; where the array is looped through and delete is called individually on each variable in the array. This is NOT how it works in reality (the real workings are a bit more complicated), but is a good way to understand the diff.

    The destructor is called on all objects, because in some cases such as in the case of an array of objects that contain pointers, calling the destructor on only the first element doesn’t free all memory.

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

Sidebar

Related Questions

Possible Duplicate: C check if file exists I was just wondering if someone could
Possible Duplicate: Where can I find a tutorial to get started learning jQuery? I
Possible Duplicate: C# variable initializations vs assignment Just like in the title, could someone
Possible Duplicate: Could anyone explain these undefined behaviors (i = i++ + ++i ,
Possible Duplicate: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25; I am
Possible Duplicate: A better way to compare Strings which could be null I have
Possible Duplicate: What does “WARN Could not determine content-length of response body.” mean and
Possible Duplicate: Threads vs Processes in Linux To implement multi-tasks programs we could use
Possible Duplicate: Disable copying data from webpage Most content in a webpage could be
Possible Duplicate: Could anyone explain these undefined behaviors (i = i++ + ++i ,

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.