Deck 12: More on C-Strings and the String Class

Full screen (f)
exit full mode
Question
The proper expression to compare the first characters of two string objects str1 and str2 is

A)strcmp(str1[0], str2[0]).
B)str1[0] == str2[0].
C)str1[0] = str2[0].
D)'str1[0]' == 'str2[0]'.
E)None of the above
Use Space or
up arrow
down arrow
to flip the card.
Question
The function concatenates the contents of one C- string with another C- string.

A)strcopy
B)stradd
C)strappend
D)strcat
E)None of the above
Question
The library function reverses the order of a character array.

A)reversit
B)reverstr
C)backward
D)strrev
E)None of the above
Question
The function _ _ accepts pointers to two strings and an integer argument, which indicates how many characters to copy from the second string to the first.

A)strncpy
B)strintcpy
C)copystring
D)strcpy
E)None of the above
Question
To declare an array that will store students' last names of up to 25 characters in length, which is an appropriate statement?

A)string lastName[24];
B)string lastName[25];
C)char lastName[26];
D)char lastName[25];
E)None of the above
Question
The null terminator stands for the ASCII code

A)100.
B)0.
C)1000.
D)57.
E)None of the above
Question
The expression strcmp("ab", "cde") returns

A)the boolean value true.
B)a nonnegative integer.
C)a negative integer.
D)the boolean value false.
E)None of the above
Question
After num = atoi("1000"); executes, what value is stored in the variable num?

A)"thousand"
B)"1000"
C)999 (1000 minus 1 for the null terminator)
D)1000
E)None of the above
Question
The code int x = 0; while (s[x] != 0){ x++;}

A)sets the variable x to point to the last character in the C- string s.
B)sets the value of the variable x to 0.
C)computes the length of the C- string s into the variable x.
D)sets the variable x to the ASCII code of the last character in the C- string s.
E)None of the above
Question
A C- string is a sequence of characters stored in consecutive memory, terminated by a

A)semicolon.
B)null character.
C)period.
D)space.
E)None of the above
Question
Assume that str1 and str2 are objects of the string class. The proper expression to use when comparing them for equality is

A)strcmp(str1, str2).
B)str1.compare(str2).
C)str1 == str2.
D)str1 = str2.
E)None of the above
Question
The string class member function returns the C- string value of the string object.

A)c_str(string s)
B)c_str()
C)c_string(string s)
D)c_string()
E)None of the above
Question
The function converts a C- string to an integer and returns the integer value.

A)atoi
B)strint
C)strtoint
D)atoint
E)None of the above
Question
The string class overloads the += operator to perform

A)concatenation of two strings.
B)calculation of the sum of the lengths of two strings.
C)conversion to integers followed by addition.
D)calculation of the sum of the integer ASCII codes that comprise the characters in the string.
E)None of the above
Question
A good way to convert a string such a "572" to an equivalent integer such as 572

A)is to use the C- library function itoa.
B)is to use an ostringstream object and the ex traction operator >>.
C)is to use an ostringstream object and the insertion operator <<.
D)is to use an istringstream object and the extraction operator >>.
E)None of the above
Question
To access the last character of a string class object str you can use the expression

A)str.last().
B)str[last].
C)str[str.length()].
D)str[str.length()-1].
E)None of the above
Question
A good way to convert a value of type double to a string is

A)use the strtodouble function.
B)use the ostringstream class.
C)use the doublestringstream class.
D)use the doubletoa function.
E)None of the above
Question
An array of characters ending with the null terminator is called

A)a string class object.
B)a C-string.
C)a C++ String.
D)a string literal.
E)None of the above
Question
The strcpy function's arguments are

A)two pointers to char.
B)three arrays and one pointer.
C)two string class objects.
D)three pointers.
E)None of the above
Question
The function accepts a C- string as an argument and returns the length of the string (not including the null terminator).

A)strlen
B)numchar
C)strlength
D)countstring
E)None of the above
Question
Assume that str1 and str2 are variables of type C- string. The proper expression to use when comparing them for equality is

A)str1.compare(str2).
B)str1 = str2.
C)str1 == str2.
D)strcmp(str1, str2)== 0.
E)None of the above
Question
By being able to pass arrays as arguments, you can write your own functions for processing C- strings.
Question
The itoa function is similar to atoi, but it works in reverse.
Question
A library function that looks for the occurrence of one string inside another is

A)strsearch.
B)strfind.
C)strstr.
D)strcmp.
E)None of the above
Question
The C++ compiler performs strict array bounds checking whenever an array of characters is being accessed.
Question
To use the strlen function in a program, you must #include

A).
B).
C).
D).
E)None of the above
Question
To use the ostringstream class, you must include the memstringstream header file.
Question
To declare a C- string, you should use the type expression string *.
Question
There exist C++ stream classes that write and read in- memory strings.
Question
The following statement declares a string object and initializes it to "Once upon a time".
string theString("Once upon a time");
Question
The >> operator can be used to convert a value of type double to an equivalent string object stored in memory.
Question
A C- string can be assigned to an variable whose type is the string class.
Question
Although C++ provides ample library functions to handle numeric values, we must write all of our own functions to manipulate character values.
Question
To account for the null terminator stored at the end of each C- string, the strlen function returns the number of characters in its argument, plus one.
Question
When using the strcatfunction, you must be careful not to overflow the bounds of the array allocated for the target string.
Question
The string class member function will return the number of characters in the string object.

A)capacity()
B)length()
C)length(string s)
D)capacity(string s)
E)None of the above
Question
It is possible to implement a string class by using a dynamically allocated array of characters.
Question
The expression str1 < str 2 is true when

A)the string object str1 precedes the string str 2 in alphabetic order.
B)the length of the string str1 is less than the length of the string str2.
C)the string str1 converted to numeric form is less than the string str2 converted to numeric form.
D)the C- string "str1" precedes the C- string "str2" in alphabetic order.
E)None of the above
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/38
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 12: More on C-Strings and the String Class
1
The proper expression to compare the first characters of two string objects str1 and str2 is

A)strcmp(str1[0], str2[0]).
B)str1[0] == str2[0].
C)str1[0] = str2[0].
D)'str1[0]' == 'str2[0]'.
E)None of the above
B
2
The function concatenates the contents of one C- string with another C- string.

A)strcopy
B)stradd
C)strappend
D)strcat
E)None of the above
D
3
The library function reverses the order of a character array.

A)reversit
B)reverstr
C)backward
D)strrev
E)None of the above
E
4
The function _ _ accepts pointers to two strings and an integer argument, which indicates how many characters to copy from the second string to the first.

A)strncpy
B)strintcpy
C)copystring
D)strcpy
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
5
To declare an array that will store students' last names of up to 25 characters in length, which is an appropriate statement?

A)string lastName[24];
B)string lastName[25];
C)char lastName[26];
D)char lastName[25];
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
6
The null terminator stands for the ASCII code

A)100.
B)0.
C)1000.
D)57.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
7
The expression strcmp("ab", "cde") returns

A)the boolean value true.
B)a nonnegative integer.
C)a negative integer.
D)the boolean value false.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
8
After num = atoi("1000"); executes, what value is stored in the variable num?

A)"thousand"
B)"1000"
C)999 (1000 minus 1 for the null terminator)
D)1000
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
9
The code int x = 0; while (s[x] != 0){ x++;}

A)sets the variable x to point to the last character in the C- string s.
B)sets the value of the variable x to 0.
C)computes the length of the C- string s into the variable x.
D)sets the variable x to the ASCII code of the last character in the C- string s.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
10
A C- string is a sequence of characters stored in consecutive memory, terminated by a

A)semicolon.
B)null character.
C)period.
D)space.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
11
Assume that str1 and str2 are objects of the string class. The proper expression to use when comparing them for equality is

A)strcmp(str1, str2).
B)str1.compare(str2).
C)str1 == str2.
D)str1 = str2.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
12
The string class member function returns the C- string value of the string object.

A)c_str(string s)
B)c_str()
C)c_string(string s)
D)c_string()
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
13
The function converts a C- string to an integer and returns the integer value.

A)atoi
B)strint
C)strtoint
D)atoint
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
14
The string class overloads the += operator to perform

A)concatenation of two strings.
B)calculation of the sum of the lengths of two strings.
C)conversion to integers followed by addition.
D)calculation of the sum of the integer ASCII codes that comprise the characters in the string.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
15
A good way to convert a string such a "572" to an equivalent integer such as 572

A)is to use the C- library function itoa.
B)is to use an ostringstream object and the ex traction operator >>.
C)is to use an ostringstream object and the insertion operator <<.
D)is to use an istringstream object and the extraction operator >>.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
16
To access the last character of a string class object str you can use the expression

A)str.last().
B)str[last].
C)str[str.length()].
D)str[str.length()-1].
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
17
A good way to convert a value of type double to a string is

A)use the strtodouble function.
B)use the ostringstream class.
C)use the doublestringstream class.
D)use the doubletoa function.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
18
An array of characters ending with the null terminator is called

A)a string class object.
B)a C-string.
C)a C++ String.
D)a string literal.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
19
The strcpy function's arguments are

A)two pointers to char.
B)three arrays and one pointer.
C)two string class objects.
D)three pointers.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
20
The function accepts a C- string as an argument and returns the length of the string (not including the null terminator).

A)strlen
B)numchar
C)strlength
D)countstring
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
21
Assume that str1 and str2 are variables of type C- string. The proper expression to use when comparing them for equality is

A)str1.compare(str2).
B)str1 = str2.
C)str1 == str2.
D)strcmp(str1, str2)== 0.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
22
By being able to pass arrays as arguments, you can write your own functions for processing C- strings.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
23
The itoa function is similar to atoi, but it works in reverse.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
24
A library function that looks for the occurrence of one string inside another is

A)strsearch.
B)strfind.
C)strstr.
D)strcmp.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
25
The C++ compiler performs strict array bounds checking whenever an array of characters is being accessed.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
26
To use the strlen function in a program, you must #include

A).
B).
C).
D).
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
27
To use the ostringstream class, you must include the memstringstream header file.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
28
To declare a C- string, you should use the type expression string *.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
29
There exist C++ stream classes that write and read in- memory strings.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
30
The following statement declares a string object and initializes it to "Once upon a time".
string theString("Once upon a time");
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
31
The >> operator can be used to convert a value of type double to an equivalent string object stored in memory.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
32
A C- string can be assigned to an variable whose type is the string class.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
33
Although C++ provides ample library functions to handle numeric values, we must write all of our own functions to manipulate character values.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
34
To account for the null terminator stored at the end of each C- string, the strlen function returns the number of characters in its argument, plus one.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
35
When using the strcatfunction, you must be careful not to overflow the bounds of the array allocated for the target string.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
36
The string class member function will return the number of characters in the string object.

A)capacity()
B)length()
C)length(string s)
D)capacity(string s)
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
37
It is possible to implement a string class by using a dynamically allocated array of characters.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
38
The expression str1 < str 2 is true when

A)the string object str1 precedes the string str 2 in alphabetic order.
B)the length of the string str1 is less than the length of the string str2.
C)the string str1 converted to numeric form is less than the string str2 converted to numeric form.
D)the C- string "str1" precedes the C- string "str2" in alphabetic order.
E)None of the above
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 38 flashcards in this deck.