Home >Backend Development >C#.Net Tutorial >How to use strlen in c language
The strlen function is used to obtain the length of a string, that is, the number of valid characters in the string: Syntax: size_t strlen(const char *str); Parameters: str: The string whose length is to be calculated, starting with 0 Ending character pointer; return value: Returns the number of characters in the string str, excluding the 0-terminating character.
Strlen function in C language
Purpose:
Strlen function is used Used to get the length of a string, that is, the number of valid characters in the string.
Syntax:
<code class="c">size_t strlen(const char *str);</code>
Parameters:
str
: To calculate the length String, 0-terminated character pointer. Return value:
Returns the number of characters in the string str
, excluding the 0-terminating character.
Usage:
Declare a character array or string, for example:
<code class="c">char str[] = "Hello World";</code>
Use The strlen function calculates the string length, for example:
<code class="c">size_t len = strlen(str);</code>
Example:
<code class="c">#include <stdio.h> #include <string.h> int main() { char str[] = "C Language"; size_t len = strlen(str); printf("String: %s\n", str); printf("Length: %zu\n", len); return 0; }</code>
Output:
<code>String: C Language Length: 10</code>
Note:
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!