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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:54:27+00:00 2026-05-27T11:54:27+00:00

I don’t quite get the point of dynamically allocated memory and I am hoping

  • 0

I don’t quite get the point of dynamically allocated memory and I am hoping you guys can make things clearer for me.

First of all, every time we allocate memory we simply get a pointer to that memory.

int * dynInt = new int;

So what is the difference between doing what I did above and:

int someInt;
int* dynInt = &someInt;

As I understand, in both cases memory is allocated for an int, and we get a pointer to that memory.

So what’s the difference between the two. When is one method preferred to the other.

Further more why do I need to free up memory with

delete dynInt;

in the first case, but not in the second case.

My guesses are:

  1. When dynamically allocating memory for an object, the object doesn’t get initialized while if you do something like in the second case, the object get’s initialized. If this is the only difference, is there a any motivation behind this apart from the fact that dynamically allocating memory is faster.

  2. The reason we don’t need to use delete for the second case is because the fact that the object was initialized creates some kind of an automatic destruction routine.

Those are just guesses would love it if someone corrected me and clarified things for me.

  • 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-27T11:54:28+00:00Added an answer on May 27, 2026 at 11:54 am

    The difference is in storage duration.

    • Objects with automatic storage duration are your “normal” objects that automatically go out of scope at the end of the block in which they’re defined.

      Create them like int someInt;

      You may have heard of them as “stack objects”, though I object to this terminology.

    • Objects with dynamic storage duration have something of a “manual” lifetime; you have to destroy them yourself with delete, and create them with the keyword new.

      You may have heard of them as “heap objects”, though I object to this, too.

    The use of pointers is actually not strictly relevant to either of them. You can have a pointer to an object of automatic storage duration (your second example), and you can have a pointer to an object of dynamic storage duration (your first example).

    But it’s rare that you’ll want a pointer to an automatic object, because:

    1. you don’t have one “by default”;
    2. the object isn’t going to last very long, so there’s not a lot you can do with such a pointer.

    By contrast, dynamic objects are often accessed through pointers, simply because the syntax comes close to enforcing it. new returns a pointer for you to use, you have to pass a pointer to delete, and (aside from using references) there’s actually no other way to access the object. It lives “out there” in a cloud of dynamicness that’s not sitting in the local scope.

    Because of this, the usage of pointers is sometimes confused with the usage of dynamic storage, but in fact the former is not causally related to the latter.

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

Sidebar

Related Questions

Don't these two mean the same thing, first get the value and then increment?
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know if anyone can help me with this or if it's even possible.
Don't be afraid to use any technical jargon or low-level explanations for things, please.
Don't they both have to convert to machine code at some point to execute
Don't know why this doesn't work. I can't do implicit animation for a newly
Don't know a whole lot about streams. Why does the first version work using
Don't shoot me, but it's the first time I saw a usage of a
Don't know if this has been asked before, so point me to another question
Don't know how to explain it better but i'm trying to get a response

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.