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.
Which assignment statements will copy the value “ toaster” into a string variable (str1)?
str1 = “toaster”;
What is the value of numbers.size( ) after the following code?
vector < float > numbers(100);
100
What is the proper way to declare a vector of strings named names?
vector names;
To add an element to a vector of integers named numbers at the next available position in the vector, you would use ________.
numbers.push_back(newValue);
Which of the following would correctly read an entire line from an input file stream named fin into a string variable named line?
getline(fin, line);
The character ‘\0’ is called the ________ character
null
The function used to “put two c-strings together into one” is called ________.
strcat
All c-strings must be terminated by ________.
‘\0’
What is the code to print out the third character in a string variable named str?
cout << str[2];
Which string function returns the first occurrence of str1 in a string named str?
find
What is the c-string function to determine the number of characters in a c-string?
strlen
The c-string to number conversion functions are in the ________ library
cstdlib
What is the difference between strcat and strncat?
strncat will concatenate at most n letters (where n has an appropriate value).
The ________ class lets you treat string values and variables like other pre-defined data types (such as int).
string
To use the functions for manipulating and comparing c-strings, you must include ________.
To compare two c-strings you use the ________ function
strcmp or strncmp
Using the == operator on a string variable results in the same value as using strcmp on two c-strings.
False
Vectors and arrays are the same data type.
False
The following declares a c-string variable that will hold 10 letters.
char str[10];
False
Using the [i] on a string variable does not check for illegal values of i.
True
A string variable and a c-string are the same data type.
False
The following code declares a vector of integers named numbers that reserves space for 100 integers.
vector < int > numbers(100);
True