Returns the length of the given byte string, that is, the number of characters in a character array whose first element is pointed to by str up to and not including the first null character. The behavior is undefined if there is no null character in the character array pointed to by str.
[edit] Parameters str - pointer to the null-terminated byte string to be examined [edit] Return valueThe length of the null-terminated string str.
[edit] Possible implementationstd::size_t strlen(const char* start) { // NB: start is not checked for nullptr! const char* end = start; while (*end != '\0') ++end; return end - start; }[edit] Example
#include <cstring> #include <iostream> int main() { const char str[] = "dog cat\0mouse"; std::cout << "without null character: " << std::strlen(str) << '\n' << "with null character: " << sizeof str << '\n'; }
Output:
without null character: 7 with null character: 14[edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4