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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:36:10+00:00 2026-06-09T06:36:10+00:00

I am new to c++ and I just learned about dynamic memory and memory

  • 0

I am new to c++ and I just learned about dynamic memory and memory leaks.

From what I understand, when creating a pointer(int *ptr = new int), and then changing the address that he is pointing, the old address still exist/allocated.
(please correct me if I am wronge).

so I thought about this:

int *ptr;
ptr = new int;

first ptr is fill with random(or not?) address, then I change it, so the old one stays?
if I try this code:

int *ptr;
cout << ptr << endl ;
ptr = new int;
cout << ptr << endl ;

I get:

0x401a4e
0x6d2d20

Does it mean that 0x401a4e is part of a memory leak? Or is it released when ptr moves to dynamic memory? How does it work?

  • 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-09T06:36:12+00:00Added an answer on June 9, 2026 at 6:36 am

    The first line (int *ptr;) does not allocate any dynamic memory so there is no memory leak. The value you see is uninitialized. It is not a valid pointer. You should not delete the pointer before assigning a value to it. Doing so would be undefined behaviour.

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

Sidebar

Related Questions

I'm new to MySQL, and just learned about the importance of data normalization. My
Im new to PHP, and I am learning about control structures. I just learned
My boss just told me that he learned about fast VB6 algorithms from a
I have just learned about XPath and I am wanting to read data from
I'm new to shell,I just learned that use (command) will create a new subshell
I am new to Box2d, and I have just learned that it does not
I'm just new to creating and launching web sites and i've hit a stumbling
I just learned about XSL and XSLT a few days ago and now I'm
So, I just learned about CURSORS but still don't exactly grasp them. What is
I learned about how to browse my local App Engine Datastore from this handy

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.