Test Series - cpp

Test Number 92/102

Q: Which is an instantiation of the basic_string class template?
A. Character
B. String class
C. Memory
D. Iterator
Solution: The string class is an instantiation of the basic_string class template.
Q: Which character is used to terminate the string?
A. $
B. Null
C. Empty
D. @
Solution: A string of characters is stored in successive elements of a character array are terminated by the NULL character.
Q: How does the strings are stored in the memory?
A. Contiguous
B. Non-contiguous
C. Null
D. sequence
Solution: The characters of a string are stored contiguously in the memory.
Q: Where are the strings stored?
A. Stack
B. Heap
C. Both Stack & Heap
D. Queue
Solution: Dynamic strings(dynamic length) are stored in heap and static string(with fixed size) are stored in stack.
Q: What will happen if a string is empty?
A. It can’t be created
B. Raises an error
C. It can be used
D. It cannot be used
Solution: An empty string is a character array with the NULL character in the zeroth index position.
Q: Which header file is used to manipulate the string?
A. iostream
B. iomanip
C. string
D. container
Solution: To use the string class, We have to use #include header file.
Q: How many maximum number of parameters does a string constructor can take?
A. 1
B. 2
C. 3
D. 4
Solution: string(other_string, position, count). It is a type of constructor for the string.
Q: Which constant member functions does not modify the string?
A. bool empty()
B. assign
C. append
D. delete
Solution: Because bool empty is a constant member function, So it can’t be modified.
Q: What is the difference between unsigned int length() and unsigned int size()?
A. Returns a different value
B. They are same
C. Returns a different value but they are same
D. Returns a length
Solution: Both of them will return the length of strings in the same notations.
Q: How many parameters can a resize method take?
A. 1
B. 2
C. 1 or 2
D. 3
Solution: There can be one or two parameters in resize method. They are string length and an optional new character to be inserted.

You Have Score    /10