Learn C Programming

Lesson 6 of 9 · Strings

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

  1. Kenji's function works on one string and crashes on another
  2. A string literal is an array the compiler makes
  3. The listing: where GCC 12 puts a literal
  4. An array initialised by a literal is a copy you own
  5. Equal literals may share one copy
  6. sizeof and strlen on a literal
  7. The rule, and how to make GCC 12 guard it
  8. On a small chip, a literal starts in flash