char* ptr = "hello";
ptr = "world";
Will the address of the ptr change?
If I originally set ptr = "hello"
, then I set ptr = "world"
. Where does "hello"
go, it just disappears?
case 1:
[before change]
ptr = [h][e][l][l][o]; // address of ptr = 10001;
[after change]
ptr = [w][o][r][l][d]; // address of ptr still = 10001;
OR
case 2:
[before change]
ptr = [h][e][l][l][o]; // address of ptr = 10001;
[after change]
ptr = [w][o][r][l][d]; // address of ptr still = 10002;
char* ptr = "hello";
ptr = "world";
// maybe 2 minutes later, i change again
ptr = "something else";