Home  >  Article  >  Backend Development  >  Detailed explanation of strlen usage in C language

Detailed explanation of strlen usage in C language

hzc
hzcOriginal
2020-06-17 14:31:3617447browse

Detailed explanation of strlen usage in C language

Detailed explanation of strlen usage in c language:

The function of strlen() function is to count the length of a given string.

Function prototype: unsigned int strlen(char *str);

Function: Count the number of characters in the string str, excluding '\0'

Return value: Return the number of characters

Example:

char *str1 = "abcdef";   // 定义一个字符指针
char str2[] = "abcdef";  // 定义一个字符数组
int len = strlen(str1);  // 统计str1字符的个数,结果为6
int len = strlen(str2);  // 统计str2字符的个数,结果为6

Recommended tutorial: "c"

The above is the detailed content of Detailed explanation of strlen usage in C language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn