Strings in Memory


For both languages it depends. There are ways to store on the stack and on the heap. But I'm creating this page anyways to point out the difference between C using a \0 while Rust uses a different approach.

C

In C the string is stored on the stack and has a \0 at the end. Which is the null character according to the ASCII table.

The string "12345" is stored in memory as 31 32 33 34 35 00. This is the same on little endian or big endian. Which makes text data more platform independent than binary data.

Rust

String in stack and heap