Test Series - cpp

Test Number 40/102

Q: How many types of representation are in the string?
A. 1
B. 2
C. 3
D. 4
Solution: C++ provides the following two types of string representations. They are C-style character string and string class type with Standard C++.
Q: What is the header file for the string class?
A. #include
B. #include
C. #include
D. #include
Solution: #include is the header file for the string class.
Q: Which is used to return the number of characters in the string?
A. length
B. size
C. both size & length
D. name
Solution: Both will return the number of characters that conform to the string’s content.
Q: Which method do we use to append more than one character at a time?
A. append
B. operator+=
C. data
D. both append & operator+=
Solution: C++ allows to append more characters to string using both inbuilt append() function and using operator overloaded += operator.
Q: What is string objects in C++?
A. Stream of alphabets
B. A stream of well-defined characters
C. Stream of characters
D. A stream of characters terminated by
Solution: String is defined as streams of characters, not necessarily terminated by . Also, a string can contain characters other than alphabets.
Q: What is Character-Array?
A. array of alphabets
B. array of well-defined characters
C. array of characters
D. array of characters terminated by
Solution: Character-Array is defined as an array of characters, not necessarily terminated by . Also, a character-array can contain characters other than alphabets.
Q: Pick the incorrect statement about Character-Array.
A. Character-Array can be terminated by a null character(‘’)
B. Character-Array has a static size
C. Character-Array has a dynamic size
D. Character-Array has a threat of array-decay
Solution: As Character-Array is an array, its size should be defined during its declaration hence the size of Character-Array is static. A Character-Array is not necessarily to be terminated by a null character. Also, it has a threat of array-decay.
Q: Pick the correct statement about string objects in C++.
A. String objects must be terminated by a null character(‘’)
B. String objects have a static size
C. String objects have a dynamic size
D. String objects use extra memory than required.
Solution: String objects are dynamic in nature i.e. their size varies as their value changes so they don’t use any extra memory and it is not necessary to terminate a string object by ‘’.
Q: Which function is used to get the length of a string object?
A. str.length()
B. str.size()
C. str.max_size()
D. both size() and length() function
Solution: Both size() and length() are used to get the size of the string objects.
Q: What is the identifier given to string class to declare string objects?
A. String
B. string
C. STRING
D. Any of the above can be used
Solution: string identifier is used as the name of the class string.

You Have Score    /10