🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# C `strlen()`函数 > 原文: [https://beginnersbook.com/2017/11/c-strlen-function/](https://beginnersbook.com/2017/11/c-strlen-function/) **函数 `strlen()`**返回给定字符串的长度(字符数)。 ## 函数 `strlen()`声明 ```c size_t strlen(const char *str) ``` `str` - 这是我们需要计算长度的给定字符串 ## `strlen()`的返回值 此函数返回表示给定字符串中字符数的整数值。 ## C `strlen()`示例 ```c #include <stdio.h> #include <string.h> int main () { char str[50]; int length; strcpy(str, "Welcome to Beginnersbook.com"); //returns the number of characters in the string length = strlen(str); printf("Length of string - %s is: %d", str, length); return 0; } ``` 输出: ```c Length of string - Welcome to Beginnersbook.com is: 28 ``` #### 相关文章: 1. [C - `strcoll()`函数](https://beginnersbook.com/2017/11/c-strcoll-function/) 2. [C - `strcpy()`示例](https://beginnersbook.com/2017/11/c-strcpy-function/) 3. [C - `strspn()`函数](https://beginnersbook.com/2017/11/c-strspn-function/) 4. [C - `strstr()`函数](https://beginnersbook.com/2017/11/c-strstr-function/)