C++ Writer program has a declaration in main () to store the string \"The most i
ID: 3684654 • Letter: C
Question
C++
Writer program has a declaration in main () to store the string "The most incomprehensible thing about the world is that it is incomprehensible. - Albert Einstein" into an array named quote. There should be a function called display () that accepts quote in an argument named q and then displays the quote using the pointer notation * (q + i); Modify the display () function written above to alter the address in quote. Always use the expression *q rather than *(q + i) to retrieve the correct element.Explanation / Answer
(a)
#include <iostream>
#include <string>
using namespace std;
void display(char q[])
{
for(int i=0;q[i]!='';i++)
{
cout<<*(q+i);
}
cout<<' ';
return;
}
int main ()
{
char quote[] = "The most incomprehensible thing about the world is that it is comprehensible, - Albert Einstein";
display(quote);
return 0;
}
(b)
#include <iostream>
#include <string>
using namespace std;
void display(char q[])
{
for(int i=0;q[0]!='';i++)
{
cout<<*(q);
q++;
}
cout<<' ';
return;
}
int main ()
{
char quote[] = "The most incomprehensible thing about the world is that it is comprehensible, - Albert Einstein";
display(quote);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.