Strings

Lesson 9 of 20

In C a string is just a char array with an invisible \0 at the end — meet the letters, the terminator and %s.

The big picture

A string is a char array

C has no string type. A string is a row of char boxes with an invisible \0 marking the end.

char arrays

char name[5] holds 5 single characters — enough for "Lena" plus the terminator.

The \0 terminator

One byte, written '\0' in code, that ends the string. Making room for it is your job.

%s prints it

printf("%s", name) writes characters one by one until it hits \0.

Strings are mutable

Assign to any index — word[0] = 'f' turns "sun" into "fun" in place.