Write a program to pass a string to a function and then to find out its length.
#include <iostream>
using namespace std;
// Write a program to pass a string to a function and then to find out its length.
void display(char ch[]){
int count = 0;
while (ch[count] != '\0') {
++count;
}
cout <<"String Length: "<< count << endl;
}
int main(){
char arr[30];
cout << "Enter a word" << endl;
cin.getline(arr, sizeof(arr));
display(arr);
return 0;
}
Comments
Leave a comment