strlen function : C Programming : Find length of string (String Operation)

strlen() : Finding Length of String

While manipulating string or character array in c programming. We need to compute the length of the string , C library provides different string handling functions. In order to compute length of the string strlen() function is used.

Syntax of the strlen() function :

int strlen(char * str);

Explanation and Summary :

Point Explanation
No of Parameters 1
Parameter Taken Character Array Or String
Return Type Integer
Description Compute the Length of the String
Header file string.h

Different Ways of Using strlen() :

There are different ways of using strlen function. We can pass different parameters to strlen() function.

Way 1 : Taking String Variable as Parameter

char str[20];
int length ;

printf("\nEnter the String : ");

length = strlen(str);

printf("\nLength of String : %d ", length);

Way 2 : Taking String Variable which is Already Initialized using Pointer

char *str = "priteshtaral";
int length ;

length = strlen(str);

printf("\nLength of String : %d ", length);

Way 3 : Taking Direct String

int length ;
length = strlen("pritesh");

printf("\nLength of String : %d",length);

Way 4 : Writing Function in printf Statement

char *str = "pritesh";
printf("\nLength of String : %d", strlen(str));