As i know from c/c++ and general knowledge of data structures, arrays are structured as sequential memory blocks with constant size. So if I create an array of five i32 variables then array size bill be 5x4 bytes, But when I create array of strings how does it's handled. Does it creates array of pointers and stores only memory address of string objects?
I asked question on rust but anyone knows a method how any language handles this situation can answer, probably it will be same method for every language.
The problem is that, as you point out, elements in an array must have a size known at compile time (called the
Sizedauto-trait in Rust).Stringis indeedSizedbecause it does not store its content in theStringstack object, but instead in memory allocated on the heap. So yes, simplified you could say that aStringarray is an array of pointers.You can see this here: