strlen

Overview :

The "strlen" is used for calculating the length of a string.

Syntax :
size_t strlen(const char *s);
Description :
The "strlen" function accepts 1 argument
  • char *s -> Pointer to a NULL terminated string.


  • The strlen() functions calculates the length of the string 's' by counting the number of bytes before the NULL('\0') character.

  • In C, strings are NULL terminated array of characters.



The 'strlen' function return number of characters in 's' excluding the NULL byte.
Example :
#include<iostream>
#include<string.h>
using namespace std;
 
int main()
{
  char str1[10],str2[10];
  
  cout<<"enter string 1 ";
  cin>>str1;
  strlen(str1);
   
cout<<strlen(str1);
    
  return 0;
}

Comments

comments powered by Disqus