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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:45:11+00:00 2026-06-13T07:45:11+00:00

Assuming I have a pointer ptr and I allocate some space for that pointer.

  • 0

Assuming I have a pointer ptr and I allocate some space for that pointer. Now, if I have another pointer ptr2 and do this:

ptr2 = ptr;

Does this mean I allocate space for ptr2 or do I need to allocate for ptr2 by myself?

  • 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-13T07:45:11+00:00Added an answer on June 13, 2026 at 7:45 am

    Well, depends what you mean by “allocate space for a pointer”.

    For example:

    int* ptr;
    

    allocates space for the pointer in automatic memory. The pointer doesn’t point to anything meaningful though. If you did:

    int* ptr = new int;
    

    you have space allocated in automatic memory for the pointer itself, and that pointer points to the memory allocated by new int, which is in dynamic memory.

    If now you did:

    int* ptr2 = ptr;
    

    you have some memory in automatic memory for ptr2 itself, but it will point to the same location in dynamic memory as ptr.

    So in the end, you have allocated memory for 2 int*s in automatic storage, and for one int in dynamic storage. The two pointers point to the same memory.

    The automatic memory is cleaned up automatically (duuh). You have to delete the dynamically allocated memory yourself:

    delete ptr;
    

    Note that since the two point to the same location, so:

    delete ptr;
    delete ptr2;
    

    would yiled undefined behavior (so is illegal).

    (this is all subject to optimizations, but, in principle, it goes down like this)

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

Sidebar

Related Questions

I could resolve this problem just now but assuming others might have the same
I have some code that does Bitmap manipulation using the LockBits method and accessing
I've been assuming stuff and seeing that now it's not correct. I have the
Assuming I have a ASP.NET MVC 3 application that runs in a web farm
Suppose we have to use in some function deeply nested pointer very extensively: function
I have been given some vendor supplied driver code written in C that runs
I have a class that extends View. This class has the member variable mCanvas
Assuming I have a project that is: using UINavigationController that has the (a) main
Assuming I have two methods. One that creates an arraylist and returns it, the
I have a class that does an implementation of a graph (template class) in

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.