Ch.8 Flashcards
What is the value of numbers.capacity( ) after the following code?
vector < float > numbers;
numbers.reserve(100)
0
When a vector is assigned to another vector
all the values in the vector are copied.
What is the value of str after the following code?
string str;
the empty string
Which is the proper way to determine how many characters are in the string variable named str?
str.length( )
What is the difference between strcmp and strncmp?
They both compare, one expects an integer for the number of characters to compare.
What is the value of numbers.size( ) after the following code?
vector < float > numbers;
numbers.reserve(100)
0
Which of the following will print out the value in str?
char str[30];
cin >> str;
cout << str;
and
int i = 0;
while(i < 30 && str[i] != ‘\0’)
cout << str[i];
How can you assign the value “toaster” to a c-string name str of size 10?
strcpy(str,”toaster”);
strcmp(first, second) returns
< 0 if first < second, 0 if first == second, positive otherwise.
What is wrong with the following attempted c-string declaration and initialization?
char str1[5] = {‘a’, ‘b’, ‘c’};
The values do not constitute a c-string.
Which of the following returns the fourth character in the string variable named str and checks if there is a fourth character in the string?
str.at(3);
What is wrong with the following code fragment?
char str1[10] = “Mark”, str2[15] = “What’s my name”;
strcpy(str1,str2);
str1 does not have enough room.
When the extraction operator is used to read data into a string,
it skips all white spaces.
Which of the following declarations correctly creates a c-string that can hold the value “phonebook”?
A) char s1[9]; B) char s1;
C) char s1 = 10; D) char s1[10];
char s1[10];
The base type for a vector can be
any data type.