string_literals

splicing

"This string is continued on the next line \
because of the \\ sign. this is called splicing"

string are joined when adjacent.

printf("When you come to a fork in the road, take it "
"--Yogi Berra");

How strings are stored

strings are an array of basic_data_type, characters, where each character is a byte. - the c compiler puts a null character at the end of the array, to mark the end of the array.

null character := a byte with characters all zero. 00000000, '\0' or 0x00

char *p;
p = "abc"; // p stores address of 'a'

char ch;
ch = "abc"[1]; // stores 'b'

// use case
char digit_to_hex_char(int digit)
{
    return "0123456789ABCDEF"[digit];
}

warnings

cc .numberLines} printf(“”); // legal printf(‘’); // wrong!

char *p p[0] = ‘a’; // wrong and undefined behavior, p is not initialised ~~~

what is the difference between a string literal and an array of characters?

An array of charcters can be changed but a string literal is constant.

c

backlinks