Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

What is strlen() Function in C++

The word "strlen" is the short of String length. The strlen() function is used to find out the length of a string. This function counts the total number of characters in the string including spaces. But, the null character ('\0') is not counted.

Syntax of strlen() Function

In C++, the general syntax of strlen() function is as follows:


var = strlen (string);



Where:
string It represents the given string whose length is to be found. It may be a string variable or constant.
var It indicates the integer variable into which the length of the string is to be stored.

Example of strlen() Function

The following source code of the C++ program inputs a string variable and finds its length using strlen() function.

#include

#include

#include

main()

 {

   char str[200];

   cout
   gets(str);

   cout
   return 0;

 }




Output:
Enter a string: C++ Tutorials
Length of string is: 13


This post first appeared on Programming Explain, please read the originial post: here

Share the post

What is strlen() Function in C++

×

Subscribe to Programming Explain

Get updates delivered right to your inbox!

Thank you for your subscription

×