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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:00:17+00:00 2026-05-26T23:00:17+00:00

I am relatively new to programming so this may well sound like a stupid

  • 0

I am relatively new to programming so this may well sound like a stupid question to you seasoned pros out there. Here goes:

In C++, when I use the delete operator on arrays, I have noticed that the data contained in the released memory locations is preserved. For example:

int* testArray=new int[5];
testArray[3]=24;
cout<<testArray[3]; //prints 24
delete [] testArray;
cout<<testArray[3]; // still prints 24

Subsequently, am I right in assuming that since testArray[3] still prints 42 , the data in the deleted memory location is still preserved? If so, does this notion hold true for other languages, and is there any particular reason for this?

Shouldn’t “freed” memory locations have null data, or is “free memory” just a synonym for memory that can be used by other applications, irrespective of whether the locations contain data or not?

I’ve noticed this is not the case when it comes to non array types such as int, double etc. Dereferencing and outputting the deleted variable prints 0 rather than the data. I also have a sneaking suspicion that I might be using wrong syntax to delete testArray, which will probably make this question all the more stupid. I’d love to hear your thoughts nonetheless.

  • 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-05-26T23:00:18+00:00Added an answer on May 26, 2026 at 11:00 pm

    Once you deallocate the memory by calling delete and try to access the memory at that address again it is an Undefined Behavior.

    The Standard does not mandate the compilers to do anything special in this regard. It does not ask the compilers to mark the de-allocated memory with 0 or some special magic numbers.It is left out as the implementation detail for the compilers. Some compiler implementations do mark such memory with some special magic numbers but it is left up to each compiler implementation.

    In your case, the data, still exists at the deallocated addresses because perhaps there is no other memory requirement which needed that memory to be re-utilized and the compiler didn’t clear the contents of previous allocation(since it is not needed to).

    However, You should not rely on this at all as this might not be the case always. It still is and will be an Undefined Behavior.


    EDIT: To answer the Q in comment.
    The delete operator does not return any value so you cannot check the return status however the Standard guarantees that the delete operator will sucessfully do it’s job.

    Relevant quote from the C++03 Standard:
    Section §3.7.3.2.4:

    If the argument given to a deallocation function in the standard library is a pointer that is not the null pointer value (4.10), the deallocation function shall deallocate the storage referenced by the pointer, render-ing invalid all pointers referring to any part of the deallocated storage.

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

Sidebar

Related Questions

I am relatively new to socket programming so this may sound like a very
I'm relatively new to web application programming so I hope this question isn't too
Please forgive me if this question is ridiculous. I'm relatively new to programming and
Relatively new to Cocoa here. This question is about NSFileHandle, but I got a
I really need your help for this. I am relatively new to programming and
Being relatively new to functional programming, I expend lots of energy wondering is this
I am relatively new to programming with Qt and had a question. Short version:
I'm relatively new to iPhone programming so I apologize if this seems a simple
I'm relatively new to iphone programming, and I've been starting out with cocos2d. I
I am relatively new to programming. My work basically revolves around data and analysis.

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.