Created: 2023-01-11 13:18
Status: #concept
Subject: Programming
Tags: C C String Character
Null Terminator
It signifies the end of a C String, allowing functions to print or read them.
char str1[6] = "hello"; // null terminator is implicitly added to last index
char str2[3] = {'h', 'i', '\0'}; // null terminator is explicitly added
Searching for the End of a String
char *string = "Hello World!";
char *s = string;
// while the current character is not \0, traverse through each character of s
while (*s) {
s++;
}
// same as above but makes s point to the character right after \0
while (*s++) {}