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

What does strlen mean in C language?

Guanhui
Release: 2020-05-30 14:51:59
Original
42994 people have browsed it

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)
Copy after login

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);
}
Copy after login

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

|This is php.cn| 的长度是 |14|
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template