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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:38:52+00:00 2026-06-13T18:38:52+00:00

Possible Duplicate: C++ delete – It deletes my objects but I can still access

  • 0

Possible Duplicate:
C++ delete – It deletes my objects but I can still access the data?

consider the following code:-

#include <iostream>
class Test
{
public:
    int k=10;
};

int main(int argc, const char * argv[])
{
    Test *t = new Test();
    delete t;
    //t1 = NULL;
    t->k=50;
    printf("\n%d",t->k);
    return 0;
}

Its output is 50 although t is deleted.
Why it’s not crashing?
I am using Xcode in Mac OS x.

  • 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-13T18:38:53+00:00Added an answer on June 13, 2026 at 6:38 pm

    “delete” would only inform (apart from calling the destructor) the Heap manager that the block of memory of sizeof(Test) which was allocated previously using new would not be used anymore and heap manger is free to do anything with that block of memory.

    Let me try to give you a scenario on when the same code could cause an exception.

    Let us say if the block of memory was allocated by heap manager on a new memory page which the heap manger acquired from the virtual memory manager, because it could not find free space anywhere else in the previously allocated pages. And now when delete is done heap manager would find that the only block which was allocated on the memory page is released, so it MIGHT decide to release the memory page back to virtual memory manager. And then when your code goes and access the memory whose page does not even exist in the virtual memory you would get an error.

    Of course there are other scenarios one can come up with through a good knowledge of heap management implementations.

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

Sidebar

Related Questions

Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: Delete object and all its child objects in Entity Framework? This code:
Possible Duplicate: Is it safe to delete a void pointer? Will the following code
Possible Duplicate: What's the best way to delete all data from a table? Clear
Possible Duplicate: Any reason to overload global new and delete? In c++ you can
Possible Duplicate: Can we delete an SMS in Android before it reaches the inbox?
Possible Duplicate: SQL Delete: can't specify target table for update in FROM clause 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.