Module 11: Strings & Character Algorithms (<string.h>)

Duration: 3.5 Hours • Text Processing
1. Null Termination 1 / 4

C-Strings as Null-Terminated Character Arrays

Why the '\0' byte is the sentinel for every string algorithm

C has no built-in "string" primitive type. A string in C is simply an array of char bytes ending with a special sentinel byte called the Null Terminator ('\0', ASCII 0).

Index012345
Character'A''p''p''l''e''\0' (Sentinel)
ASCII651121121081010
⚠️
Remember Array Sizing for Null Terminator
To store an N-character word, the array size MUST be at least N + 1 bytes to accommodate the trailing '\0'. Declaring char s[5] = "Apple"; is an error because it lacks room for '\0'!