String Manipulation

Lesson 11 of 20

Strings are just char arrays with a hidden '\0' — count, copy and compare them by watching every character move.

The big picture

What is a C string?

C has no string type. A string is an array of char that ends with the invisible null terminator '\0'.

Just char arrays

A C string is a char array whose last element is '\0' — the terminator that marks the end.

Length is computed

strlen walks the array counting characters until it hits the terminator. No length is stored anywhere.

The library helps

string.h gives you strcpy, strcmp, strcat and more — but each one is just a small loop you could write yourself.

Always leave room

A string with n visible characters needs n + 1 cells: one extra for the terminator.