strlen() Function In C and C++ Tutorial with Examples – POFTUT

strlen() Function In C and C++ Tutorial with Examples

C and C++ programming languages provide the strlen() function in order to calculate or return the size of the given string or char array. String and char array is the same data type in C and C++ which simply a character array. strlen() function provided from the <string.h> header or library.

strlen() Function Syntax

strlen() function has the following syntax where we provide the char array or string as a parameter.

  • size_t is the return value type of the strlen() function which is generally integer or long which returns the size or length of the given string or char array.
  • const char *STR specifies the string or char array we want to get length or size.

String Length Of A String

We will start by calculating the length of the given string. Actually we will provide a char array where it will be presented in string format. We will provide the string named a and b with values My name is poftut.com and I love poftut.com. We will calculate these strings or sentences length with the strlen() function.

LEARN MORE  PHP Glob() Function To Match Path, Directory, File Names with Examples

String Length Of A String with Char Pointer

Alternatively, we can create the string by using char pointer which will actually a char array or string too. We will provide the string named a and b with values My name is poftut.com and I love poftut.com. We will calculate these strings or sentences length with the strlen() function.

String Length Of A Char Array

Alternatively, we can create or define a char array item by item and then calculate the size of the complete char array. We will set the Hello poftut.com sentence characters character by character into char array a.

Length Of A Input String or Char Array

We can also get the char array or string from the input by using scanf(). We will read the input from the standard input or console and set into a char array then we will calculate the length with the strlen() function.

LEARN MORE  Search Text Files Content With Findstr Command In Windows

Length Of A Input String or Char Array

Length Of A Input String or Char Array

echo '
'

Leave a Reply

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