Pointers to Constant Strings

Learn about string literals and pointer to constant strings.

We'll cover the following...

String literals

In the previous lesson, we saw that it’s possible to initialize a string as follows:

char str[10] = "abc";

The "abc" value is called a string literal. It is a sequence of characters terminated by the null character ('\0'). They are constant strings that we can’t modify.

Most commonly, they’re placed in the .rodata section of the executable file because they are constant and shouldn’t be modified, only read.

If the same string literal appears multiple times in the code, a smart compiler will only allocate it once inside .rodata and make all references inside ...