Wednesday, 4 December 2019

Write a program that has a declaration in main() to store the string "Vacation"

Q: Write a program that has a declaration in main() to store the string "Vacation" i near in an array named message. Also, add a function call to display() that accepts message in an argument named strng and then displays the contents of message by using pointer notation *(strng + i), modify the display() function to use the expressions *strng rather than *(strng + i). The program I compiled from this question is listed below, I am struggling with placements of notations on the latter part of the question.

#include <iostream>
using namespace std;

int main(){
void dispstr(char*);
char str[] = "Vacation";

display(str);
return 0;
}

void display(char* ps)
{
while( *ps )
cout << *ps++;
cout << endl;
}

Solution:

 #include <iostream>
using namespace std;

int main(){
void dispstr(char*);
char str[] = "Vacation";

display(str);
return 0;
}

void display(char* ps)
{
while( *ps )
cout << *ps++;
cout << endl;
}

No comments:

Post a Comment