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:
size_t strlen(const char *str);
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:
#include
#include
int main() {
char str[] = "Hello World!";
int len = strlen(str);
printf("String length: %d\n", len); // 输出 12
return 0;
}
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!