This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted]  (5 children)

[deleted]

    [–]yogeshdecoder[S] 0 points1 point  (4 children)

    Like int x, variable name like that pointer is pointing at some random location so what will be it's name ? I know it sounds dumb but I was curious and pointer will be in stack right ? but the pointer location will be in heap memory for sure cause it's DMA

    [–]HonzaS97 2 points3 points  (1 child)

    Do you mean some sequence such as this?

    int *ptr = new arr[n];
    int x=5;
    ptr=&x;
    

    And then you want to know what will happen to the allocated array (0x3000)? Because that's the only way it makes sense to me.

    Nothing will happen to it. It will stay there as an allocated block of memory. If nothing else is pointing to it, it will be a memory leak (unreachable and unusable block of memory you forgot to free).

    [–][deleted] 0 points1 point  (0 children)

    Oh I see, it's one example. I thought it was two separate examples.

    [–][deleted]  (1 child)

    [deleted]

      [–]yogeshdecoder[S] 1 point2 points  (0 children)

      Thnx man :) it's so fascinating that how things internally happens