Write a C++ program that prompts the user to enter the string and outputs the length of the characters entered. (Use pointers to calculate the length of the string).
Source Code:
#include <iostream>
using namespace std;
int main()
{
char
string[1000], *ptr;
int i=0 ;
cout
<< "Enter Any string :
"<<endl;
cin>>string;
ptr = string;
while (*ptr
!= '\0')
{
i++;
ptr++;
}
cout <<
"Length of String : " << i<<endl;
return 0;
}
output:
0 Comments