The strlen function is used to get the length of a string. It returns the number of characters in the string that does not contain the null terminator. Usage: strlen(str), where str is the string whose length is to be determined.
Question: What is strlen function?
Answer: The strlen function is a function in C language used to obtain the length of a string.
strlen The function prototype is as follows:
<code class="c">size_t strlen(const char *str);</code>
Parameters:
str
: The string whose length is to be determined. It must be null terminated. Return value:
str
excluding the null terminator. The following are some examples of using the strlen function:
<code class="c">#include <stdio.h> #include <string.h> int main() { char str[] = "Hello World!"; int len = strlen(str); printf("String length: %d\n", len); // 输出 12 return 0; }</code>
str
is empty (length is 0), the strlen function returns 0. wcslen
function to calculate the length of a Unicode string. The above is the detailed content of Usage of strlen function in c language. For more information, please follow other related articles on the PHP Chinese website!