Saved Bookmarks
| 1. |
Consider the following C++ statements: char word [20]; cin>>word; cout<<word; gets(word); puts(word); If the string entered is “HAPPY NEW YEAR”, predict the output and justify your answer. |
|
Answer» cin>>word; cout<<word; It displays “HAPPY” because cin takes characters upto the space. That is space is the delimiter for cin. The string after space is truncated. To resolve this use gets () function. Because gets () function reads character upto the enter key. Hence gets(word); puts(word); Displays “HAPPY NEW YEAR” |
|