C String – strlen() function

strlen() function in C is used to calculate the length of the given string. It counts the number of characters present in a String excluding the null character ‘\0‘.

The strlen() function is defined in the header file string.h. It takes one argument that is the string name and written as follows:

strlen(string_name);


C Program for strlen() function

#include <stdio.h>
#include <string.h>

int main()
{
    char str[20] = "Simple2Code";

    printf("Length of a String str: %zu", strlen(str));

    return 0;
}

Output:

Length of a String str: 11