Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

String literals are constant data, embedded in the program, and thus stored inside the read-only memory zone.

Strings literals are written between quotes and can be used to initialize string variables:

"abcdef"

8.4.1Multi-lines definition

We have seen a string literal defined on one line, but it can also be defined on multiple lines (new line characters are included):

"my string\non\nmultiple\nlines."

Using the backslash (\) escape character, we can avoid the new line characters:

"my string on multiple lines."

8.4.2Using escape characters

The escape characters we have seen for the char type can be used inside a literal string definition:

my string
 ? ℝ

The NULL character (character ASCII 0) is not interpreted as a string terminator and is printed as-is:

abcdef

8.4.3Raw string

Using the r prefix we can define a raw string in which escape characters are not interpreted (much like Python’s raw strings):

"My string with any char\\n \\x3f.'abc'"

8.4.4Byte string

Byte string (slice of bytes (u8)):

[97, 98, 99]