char* pointers between C and D
Ali Çehreli
acehreli at yahoo.com
Tue Aug 9 13:27:09 UTC 2022
On 7/25/22 06:51, ryuukk_ wrote:
> On Monday, 25 July 2022 at 11:14:56 UTC, pascal111 wrote:
>> const(char)[] ch1 = "Hello World!";
>> char[] ch2="Hello World!".dup;
[...]
> `ch1`is a string literal, just like in C, it is null terminated
To be pedantic, ch1 is not the string literal but a slice of it. "Hello
world" is the string literal and does have a '\0' at the end.
> `ch2` is a GC allocated char array, it is NOT null terminated
Yes. The only difference between ch1 and ch2 is that ch1 does not incur
an allocation cost.
Ali
More information about the Digitalmars-d-learn
mailing list