strlen() Function In C Programming

C programming language provides the strlen() function in order to calculate the given string length or character count. The strlen() function takes the string or character array as an argument and returns its length as an integer. The returned type is actually as size_t type which is unsigned integer type . The strlen() is also provided with the C++ programming language.

strlen() Function Syntax

The strlen() function has the following syntax where the length of the string is returned by strlen() function. The strlen() function is provided via the <string.h> library.

  • STRING is the string or char array which size will be calculated.

strlen() Function Example

In the following example, we will calculate the size of the given string or character array.

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

int main()
    char x[20]="WiseTut";
    char y[20]={'W','i','s','e','T','u','t','\0'};

    // using the %zu format specifier to print size_t
    printf("Length of string a = %zu \n",strlen(x));
    printf("Length of string b = %zu \n",strlen(y));

    return 0;
Length of string x = 7
Length of string y = 7

Leave a Comment