Home >Backend Development >C#.Net Tutorial >What does strlen mean in C language?

What does strlen mean in C language?

Guanhui
GuanhuiOriginal
2020-05-30 14:51:5943013browse

What does strlen mean in C language?

#What does strlen mean in C language?

The strlen function is a standard library function in C language. Its function is to calculate the length of a string, but does not include "\0".

Syntax and description

C library function size_t strlen(const char *str) calculates the length of the string str until the null terminating character, but does not include the null terminating character .

size_t strlen(const char *str)

Parameters

str -- The string whose length is to be calculated.

Return value

This function returns the length of the string.

Example

The following example demonstrates the usage of strlen() function.

#include <stdio.h>
#include <string.h>
int main ()
{
   char str[50];
   int len;
   strcpy(str, "This is php.cn");
   len = strlen(str);
   printf("|%s| 的长度是 |%d|\n", str, len);
   
   return(0);
}

Let us compile and run the above program, which will produce the following results:

|This is php.cn| 的长度是 |14|

Recommended tutorial: "C#"

The above is the detailed content of What does strlen mean 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