Strings
- Raw C strings (char arrays) should always terminate with a null character, ‘\0’. Fun fact about char arrays:
nullptr
is inserted at the back of the array. This is a convention forargv
1
2
3
4
5
6
7
8
char str[] = "a string";
printf("%s", str); // searches for "\0" to terminate
char *strs[] = {"str1", "str2", nullptr};
for (size_t i = 0; strs[i] != nullptr; ++i){
// uses nullptr to terminate string array.
printf("%s", strs[i]);
}