Tech Study

How To Find length of Length of String c++

c++ string length() function, helps to find length of string c++ and return an integer value as a byte. It is array of characters that ends with a null character.


This method can be used to find length of string c++:

  • std::string methods
  • C library function
  • Loops function


syntax for length of string c++


c++ string size

Some coder use size() function to get string length c++

C++ string length vs c++ string size  

C++ String Length() and c++ string size() functions are the same, just synonyms with each other.


In this tutorial, we will learn how to find length of string c++ and c++ string size

we have used CodeBlocks compiler for debugging purposes. But you can use any C++ programming language compiler as per your availability.

Example 1:

In this example, we ask users to write a maximum length of string c++ of 100 characters.

#include <iostream>
#include <math.h>
using namespace std;
//function declaration
int stringLength(char *);
int main()
    char text[100];
    int length;
    cout<<"Enter text (max- 100 characters): ";
    length = stringLength(text);
    cout<<"Input text is: "<<text<<endl;
    cout<<"Length is: "<<length<<endl;
    return 0;
int stringLength(char *str)
    int len=0;
    //calculating string length
    for(len=0; str[len]!='\0'; len++);
    //returning len
    return len;

length of string c++ and c++ string size

The function “stringLength” is used to find the length of input and return both input and length as a result.


The program gets executed and the function returns “0” as result.

length of string c++and c++ string size

TaggedWrite C program to find Length of the String by passing String/Character

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more