Home >Backend Development >C#.Net Tutorial >How to use strlen in c language
strlen() function is used in C language to calculate the length of a given string, excluding the null terminator: Declare a char array or pointer to store the string. Get the string. Pass a string pointer as an argument to the strlen() function. Store the returned length in a variable.
strlen() usage in C language
strlen() is a function in the C standard library , used to calculate the length of a given null-terminated string.
Syntax
<code class="c">size_t strlen(const char *str);</code>
Parameters
str
: Pointer to null terminated string pointer. Return value
strlen() returns the length of the string, excluding the null terminator.
Usage
To use the strlen() function, follow these steps:
Example
<code class="c">#include <stdio.h> #include <string.h> int main() { char str[] = "Hello World"; size_t length = strlen(str); printf("字符串 '%s' 的长度为 %d\n", str, length); return 0; }</code>
Output
<code>字符串 'Hello World' 的长度为 11</code>
Notes
The above is the detailed content of How to use strlen in c language. For more information, please follow other related articles on the PHP Chinese website!