C

The Strlen() Function In C – A C Tutorial

The strlen() function returns the length (number of characters) of a given string.

Declaration of the function strlen()

size_t strlen(const char *str)

str – The given string for which the length must be calculated.

Strlen’s return value ()

The integer value representing the number of characters in the given string is returned by this function.

Example of strlen() in C

#include <stdio.h>
#include <string.h>
int main () {
   char str[50]; 
   int length;

   strcpy(str, "Welcome to Beginnersbook.com");

   //returns the number of characters in the string 
   length = strlen(str);
   
   printf("Length of string - %s is: %d", str, length);
   return 0;
}

Output:

Length of string - Welcome to Beginnersbook.com is: 28

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button