How to find the length of a string in C language?

In C language, you can use the strlen() function to find the length of a string. The strlen() function is located in the header file, and its prototype is as follows:

Calculate the length of the string represented by the input character array and return it as a size_t data type.

It is a pointer to a string that is terminated by a null character.

The sample code is as follows:

Include the libraries stdio.h and string.h.

int main() {
char str[] = “Hello World”;
int len = strlen(str);
printf(“The length of the string is: %d\n”, len);
return 0;
}

The result of the operation shows that the length of the string is 11.

bannerAds