The function strlen() returns the length (number of characters) of the given string.
Function strlen() Declaration
size_t strlen(const char *str)
str – This is the given string for which we need to compute the length
Return value of strlen()
This function returns the integer value representing the number of characters in the given string.
C strlen() example
#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; }
Output:
Length of string - Welcome to Beginnersbook.com is: 28
Leave a Reply