Write C++ program to find length of string using pointer


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


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

Introduction

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


  1. #include <iostream>
  2. #define MAX_SIZE 100 // Maximum size of the string
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. char text[MAX_SIZE];
  8. char * str = text;
  9. int count = 0;
  10.  
  11. // Inputtin string from user
  12. cout<<"Enter any string: ";
  13. cin>>text;
  14.  
  15. // Iterating though last element of the string
  16. while(*(str++) != '\0') count++;
  17.  
  18. cout<<"Length of "<<text<<" is "<<count;
  19.  
  20. return 0;
  21. }
  22.  

Result

C++ language techstudy.org

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.