Module 10 · Strings
Under the Hood: Where a String Literal Actually Lives
ProReading
Kenji's capitalise turns the first letter of a word into a capital. It has worked on every array he gave it. Today he wanted to save a line, so he handed it the text itself: capitalise("world"). The Playground answered Runtime error, and even the line printed before the call was gone.
Checking what this lesson needs for you…
What is inside Under the Hood: Where a String Literal Actually Lives
- Kenji's function works on one string and crashes on another
- A string literal is an array the compiler makes
- The listing: where GCC 12 puts a literal
- An array initialised by a literal is a copy you own
- Equal literals may share one copy
- sizeof and strlen on a literal
- The rule, and how to make GCC 12 guard it
- On a small chip, a literal starts in flash