String Literals

String Literals

1
char *text = "Hello";

Know: The memory address of the first character of the string literal “Hello” is assigned to the pointer variable text.

However: This string literal is stored in read-only memory.

Thus: Cannot modify the literal. Doing so leads to UB.

Modern Standard: You are not supposed to assign a literal to non-const pointer.

1
const char *text = "Hello"; // this way complier stops accidental modfications of the literal

Why in ROM: Search engine your way

Want to Modify?: Declare it as a character array instead.

1
2
char text[] = "Hola"; // allocates mutable memory on stack
text[0] = 'C';

String Literals
http://example.com/p/ea99e230968447eab9eece94f1f5f837/
Author
John Doe
Posted on
June 4, 2026
Licensed under