Open In App
Related Articles

strlen() function in c

Improve Article
Save Article
Like Article

The strlen() function in C calculates the length of a given string. The strlen() function is defined in string.h header file. It doesn’t count the null character ‘\0’.

Syntax of C strlen()

The syntax of strlen() function in C is as follows:

size_t strlen(const char* str);


The strlen() function only takes a single parameter.

  • str: It represents the string variable whose length we have to find.

Return Value

  • This function returns the integral length of the string passed.
strlen in c

C strlen() Function

Example of C strlen()

The below programs illustrate the strlen() function in C:


// c program to demonstrate
// example of strlen() function.
#include <stdio.h>
#include <string.h>
int main()
    // defining string
    char str[] = "GeeksforGeeks";
    // getting length of str using strlen()
    int length = strlen(str);
    printf("Length of string is : %d", length);
    return 0;


Length of string is : 13

Important Points about strlen()

The following points should be kept in mind while using strlen():

  • strlen() does not count the NULL character ‘\0’.
  • The time complexity of strlen() is O(n), where n is the number of characters in the string.
  • Its return type is size_t ( which is generally unsigned int ).
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 29 May, 2023
Like Article
Save Article
Similar Reads