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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:39:35+00:00 2026-06-13T06:39:35+00:00

I’m trying to understand what this code does (and if it’s even allowed): int

  • 0

I’m trying to understand what this code does (and if it’s even allowed):

int * A;
int * B;
A = (int *)malloc( size_t somenumber );
B = A;

// bunch of stuff using B, B++, etc.

Everything I’ve read always shows equating things to pointers either using the reference operator (&) or the derefernce operator (*).

What does this sort of equating do?

And, when I ultimately free(A) what happens to B?

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

    Pictures are always good when it comes to pointer confusion:

    int * A; // create a pointer to an int named "A"
    int * B; // create a pointer to an int named "B"
    A = (int *)malloc( size_t somenumber ); // Allocate A some memory, now B is an 
                                            // uninitialized pointer; A is initialized,
                                            // but just to uninitialized memory
    

    Conceptually:

    enter image description here

    B = A; // Assign B to the value of A (The uninitialized memory)
    

    enter image description here

    free(A);
    

    enter image description here

    So after all that I think you can see what’s happening. B is being assigned the value of A, which is the allocated and uninitialized memory chunk. So now you just have two pointers pointing to the same area.

    As to the free() question, as you can see when you call free(A); you’re left with both A and B pointing to the same area, there’s just nothing allocated to your program there anymore. This is why when calling free() it’s good to set your pointer to NULL.

    Now way back to your initial question. If you wanted to check of two pointers were ==:

    int * A; // create a pointer to an int named "A"
    int * B; // create a pointer to an int named "B"
    A = (int *)malloc( size_t somenumber ); // Allocate A some memory, now B is an 
                                            // uninitialized pointer; A is initialized,
                                            // but just to uninitialized memory
    
    if(B == A){
       // The pointers are pointing to the same thing!
    }
    if(*B == *A){
       // The values these pointers are pointing to is the same!
    }
    

    UPDATE
    So to answer your updated questions, We need to change the definition of B.

    int *A;  // A is a pointer to an int
    int **B; // B is a pointer to a pointer to an int
    B = &A;  // B is now pointing to A
    

    So to illustrate that:

    enter image description here

    For B=*A:

    int *A;
    int B;
    A = malloc(sizeof(int));
    *A = 5;
    B = *A;
    

    This is a deference of A. So you’re just taking whatever A is pointing to and assigning it to B, in this case 5

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) 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.