What is the correct way to delete a pointer in an array?

//the setup
tiles = new Tile **[num_bands];
for( int i = 0 ; i < num_bands ; i++ )
tiles[i] = new Tile *[num_spokes];  

for(int i=0; i < num_bands; i++){
    for(int ii=0; ii < num_spokes; ii++){
        tiles[i][ii] = 0; 
    }
}


 //the problem
delete tiles[1][1];

When I delete a tile, tiles [1] [1] still contain the address. I thought it should be a null pointer or 0x0, but it is not. Am I deleting it wrong?

+3
source share
5 answers

deletemust not indicate a pointer; it is your own responsibility to do this if you want.

Basically, it deletesimply means "I no longer need memory at this address, so you can use it for something else." - He says nothing about which value indicators indicate an exempted address.

+12
source

++ delete NULL , : SO

+3

, . ++ , , .

+1

, :

1) .

2) , . .

3). , .

0

++, = 0 . , , .

0

Source: https://habr.com/ru/post/1753212/


All Articles