C program to find length of string using strlen function

using strlen() function, we can find the length of a string.

size_t strlen(char *);


strlen function takes an string(char *) argument.

strlen function return type

It will return an unsigned int which is the length of a given string.


strlen function is defined in string.h library.




int main()
    char name[20]="Programming";
    int length;

    length = strlen(name);

    printf("Length of %s = %d\n",name,length);

    return 0;


Length of Programming = 11

Incompatible implicit declaration of built-in function strlen

If we forget to add the string.h header file, we will get the following error.

"incompatible implicit declaration of built-in function strlen"



If we want to use strlen function in our source program, we should include string.h library.

Otherwise, it will throw the above warning message.

Topics You Might Like