Write a program to demonstrate the use of pointer to pointer. Make a list of characters (a word) by char *word, another list of words (a sentence) using char **sentence. Print the sentence using a double pointer.
using namespace std;
/*
Write a program to demonstrate the use of pointer to pointer.
Make a list of characters (a word) by char *word, another list of words (a sentence) using char **sentence.
Print the sentence using a double pointer.
*/
int main()
{
char w[] = "Hello World";
char *word, **sentence;
int r;
word = &w[0];
sentence = &word;
cout<<"\n\tWord = "<<w;
cout<<"\n\tWord available at *ptr = ";
for(r=0;r<11;r++) cout<<*(word+r);
cout<<"\n\tSentence available at **sentence = ";
for(r=0;r<11;r++) cout<<*(sentence+r);
return(0);
}
Comments
Leave a comment