|
|
|
|
|
by coolThingsFirst
10 days ago
|
|
C is pretty bizarre but I expect someone writing it professionally to know that even passing void compareStrings(char str1[], char str2[]) is equivalent to compareStrings(char * str1, char * str2) so no way to get the length of it with sizeof(str1) and strlen walks the string until it finds the null terminator. |
|
NUL-terminated strings don't know their lengths and so, without an "n" variant function and running strlen() ahead-of-time, must iterate the entire thing. Pascal format strings (supported up to 255 byte lengths in the classic form) could find length as an O(1) operation because there was no terminator necessarily.