Content Frame
Note for screen reader users: There is text between the form elements on this page. To be sure that you do not miss any text, use item by item navigation methods, rather than tabbing from form element to form element.
Skip Breadcrumb Navigation
Home  arrow Student Resources  arrow Quizzes  arrow Chapter 9

Chapter 9

Strings

This activity contains 10 questions.

Question 1.
What will the following code fragment output?
char s[20] = "hello\0 world";
cout << s << endl;

 
End of Question 1


Question 2.
What is the output of the following snippet of code?

char s[20];
s[0]= 'h';
s[1]= 'i';

cout << s << endl;

 
End of Question 2


Question 3.
What is the error regarding the following C-String?

char s[2] = "hi";

 
End of Question 3


Question 4.
Which of the following snippets of code will continually loop until the user enters the text "yes"?

 
End of Question 4


Question 5.
Which of the following will copy the text "pizza" into a C-String variable?

 
End of Question 5


Question 6.

Given the following code:

char name[100], hometown[100], state[100];

cin >> name;
cin >> hometown;
cin >> state;

cout << name << endl;
cout << hometown << endl;
cout << state << endl;

What will it output if the input entered by the user is:

   Lynn Guini
   Pastaville
   Alaska
 
End of Question 6


Question 7.
Which of the following snippets of code will continually loop until the user enters the text "yes"?

 
End of Question 7


Question 8.

Given the following code:

string name, hometown, state;

getline(cin,name);
getline(cin,hometown);
getline(cin,state);

cout << name << endl;
cout << hometown << endl;
cout << state << endl;

What will it output if the input entered by the user is:

   Lynn Guini
   Pastaville
   Alaska
 
End of Question 8


Question 9.
Which of the following will copy the text "pizza" into a string object variable?

 
End of Question 9


Question 10.
In the following code:

 int num;
 string s;

 cin >> num;
 cin.ignore();
 getline(cin, s);

When run with the input of:

  10
  hello there

This program will store 10 into num and "hello there" into s. Why is the statement cin.ignore() needed?

 
End of Question 10





Pearson Copyright © 1995 - 2010 Pearson Education . All rights reserved. Pearson Addison Wesley is an imprint of Pearson .
Legal Notice | Privacy Policy | Permissions

Return to the Top of this Page