Can't understand if deallocation happens?

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 22 07:59:47 PST 2017


On Sunday, 22 January 2017 at 15:51:01 UTC, Suliman wrote:
>  	string str = "abc";
>  	writeln(str.ptr);
>  	str = "def";
>  	writeln("last data: ", *(str.ptr));
>  	writeln("old data: ", *(str.ptr-1)); // print nothing
>  	writeln("old data: ", *(str.ptr-2)); // print c
>
> It's look like that there is some gap between data, because `d` 
> minus 1 should be `c`, but `c` I am getting only if I am doing 
> `-2`. Why?

writeln("old data: ", cast(int)*(str.ptr-1));

#old data: 0

String is gaping by zero?? I thought they are continuously like

abcdef
---↑

Where `↑` is equal to `ptr`.


More information about the Digitalmars-d-learn mailing list