This function counts the number of characters present in a string. Its usage is illustrated in the following program.
\* C Program to demonstrate strlen() function *\
# include < stdio.h >
int main( )
{
char arr[ ] = "Generalnote" ;
int len1, len2 ;
len1 = strlen ( arr ) ;
len2 = strlen ( "C Tutorial" ) ;
printf(" \nstring = %s length = %d ", arr, len1) ;
printf(" \nstring = %s length = %d ", "C Tutorial", len2) ;
return ( 0 ) ;
}
string = Generalnote length = 11
string = C Tutorial length = 10
In the first call to the function strlen( ), we are passing the base address of the string, and the function in turn returns the length of the string. While calculating the length it doesn’t count ‘\0’.