C++ deleting a pointer when there are 2 pointers pointing to the same memory locations

后端 未结 4 1930
既然无缘
既然无缘 2020-12-17 07:26

Lets say, I have one pointer

int *l1 = new int[100*100];

int *l2 = l1;

Now, l1 & l2 both point to the same sequ

4条回答
  •  伪装坚强ぢ
    2020-12-17 07:56

    int *l1 = new int[100*100];
    

    With this statement, Integer array of 100*100 is created, i.e. (10,000 *4 bytes). In C int is 4 byte. enter image description here

    With statement,

    int *l2 = l1;
    

    enter image description here

    delete [] l1;
    

    enter image description here

提交回复
热议问题