Answer to Question #161238 in C++ for Ashes

Question #161238

Write a program to pass a string to a function and then to find out its length.


1
Expert's answer
2021-02-09T03:15:43-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog