WAP to count number of Characters in a word using pointer to string.
#include<iostream>
using namespace std;
int main() {
char str[20], *pt;
int i = 0;
cout << "Pointer Example Program : Count the Number of Characters in a word \n";
cout << "Enter Any string [below 20 chars] : ";
cin >>str;
pt = str;
while (*pt != '\0') {
i++;
pt++;
}
cout << "Length of String : "<< i;
return 0;
}
Comments
Leave a comment