In C++, strings are handled in two primary ways: traditional C-style strings (null-terminated character arrays) and the modern std::string class introduced in the Standard Template Library (STL). The std::string class, included via the <string> header, provides a highly flexible, dynamic, and memory-safe way to manipulate text compared to raw character arrays. It abstracts memory management and offers a rich set of built-in member functions like append(), find(), substr(), and length() for efficient string operations. Furthermore, C++ supports seamless concatenation using the + operator and simple relational comparisons without needing standard C-library functions like strcmp. Understanding both C-style arrays and std::string is essential for handling text, parsing data, and mastering C++ memory concepts.
C++ Strings MCQs
1 min read
Correct Answer: a) <string>
Explanation:
std::string is declared in the string header.
Correct Answer: b) std
Explanation:
std::string is part of the std namespace.
Correct Answer: c) It can grow or shrink dynamically
Explanation:
std::string manages dynamic character storage.
Correct Answer: d) A null-terminated character array
Explanation:
C-style strings end with a null character.
Correct Answer: a) size()
Explanation:
size returns the current character count.
Correct Answer: b) length()
Explanation:
length is equivalent to size for std::string.
Correct Answer: c) empty()
Explanation:
empty returns true when size is zero.
Correct Answer: d) append()
Explanation:
append adds content at the end.
Correct Answer: a) +
Explanation:
The plus operator joins strings.
Correct Answer: b) +=
Explanation:
The += operator appends to the left operand.
Correct Answer: c) substr()
Explanation:
substr creates a new string from a range.
Correct Answer: d) find()
Explanation:
find returns the position of a match or npos.
Correct Answer: a) A constant meaning no position
Explanation:
npos is returned when a search fails.
Correct Answer: b) at()
Explanation:
at throws out_of_range for invalid indexes.
Correct Answer: c) operator[]
Explanation:
operator[] does not check the index.
Correct Answer: d) front()
Explanation:
front accesses the first character.
Correct Answer: a) back()
Explanation:
back accesses the last character.
Correct Answer: b) push_back()
Explanation:
push_back adds a character at the end.
Correct Answer: c) pop_back()
Explanation:
pop_back removes the final character.
Correct Answer: d) clear()
Explanation:
clear makes the string empty.
Correct Answer: a) erase()
Explanation:
erase deletes characters from a string.
Correct Answer: b) replace()
Explanation:
replace substitutes existing characters with new content.
Correct Answer: c) insert()
Explanation:
insert adds characters at a specified position.
Correct Answer: d) compare()
Explanation:
compare returns an ordering result.
Correct Answer: a) c_str()
Explanation:
c_str provides a const char pointer with a null terminator.
Correct Answer: b) data()
Explanation:
data returns a pointer to the character storage.
Correct Answer: c) capacity()
Explanation:
capacity is the allocated storage size.
Correct Answer: d) reserve()
Explanation:
reserve increases capacity without changing size.
Correct Answer: a) resize()
Explanation:
resize adds or removes characters to reach a size.
Correct Answer: b) shrink_to_fit()
Explanation:
shrink_to_fit asks to release excess capacity.
Correct Answer: c) begin()
Explanation:
begin points to the first character.
Correct Answer: d) end()
Explanation:
end points one past the last character.
Correct Answer: a) rbegin()
Explanation:
rbegin starts reverse traversal at the last character.
Correct Answer: b) rend()
Explanation:
rend marks the end of reverse traversal.
Correct Answer: c) Yes
Explanation:
std::string tracks size, so embedded nulls are allowed.
Correct Answer: d) std::string automatically manages storage
Explanation:
std::string handles allocation and deallocation.
Correct Answer: a) assign()
Explanation:
assign replaces the string content.
Correct Answer: b) copy()
Explanation:
std::string::copy writes characters to an array.
Correct Answer: c) std::getline
Explanation:
getline reads until a newline by default.
Correct Answer: d) std::getline with a delimiter
Explanation:
getline accepts an optional delimiter character.
Correct Answer: a) Reads a token until whitespace
Explanation:
Extraction stops at whitespace by default.
Correct Answer: b) cin.ignore()
Explanation:
ignore discards characters from the stream.
Correct Answer: c) A non-owning view of characters
Explanation:
string_view refers to existing character data.
Correct Answer: d) No
Explanation:
string_view does not manage lifetime.
Correct Answer: a) A single character type
Explanation:
char stores one character.
Correct Answer: b) A null-terminated character array
Explanation:
strlen counts until the null terminator.
Correct Answer: c) Copies a C-style string
Explanation:
strcpy copies characters including the terminator.
Correct Answer: d) Compares C-style strings
Explanation:
strcmp performs lexicographical comparison.
Correct Answer: a) Appends one C-style string to another
Explanation:
strcat adds the source to the destination.
Correct Answer: b) 6
Explanation:
sizeof includes the null terminator in the array size.
Correct Answer: c) Compares contents
Explanation:
Equality checks character sequences.
Correct Answer: d) Lexicographically
Explanation:
Comparison follows character order.
Correct Answer: a) An array of const char
Explanation:
String literals are const char arrays that can decay to pointers.
Correct Answer: b) Yes
Explanation:
std::string has constructors for C-style strings.
Correct Answer: c) 0
Explanation:
An empty string has no characters.
Correct Answer: d) Greater than or equal
Explanation:
Capacity may include extra room for growth.
Correct Answer: a) Increase capacity
Explanation:
reserve requests more storage.
Correct Answer: b) No, it requests at least that amount
Explanation:
The implementation may allocate more.
Correct Answer: c) A maximum possible number of characters
Explanation:
max_size is an implementation limit.
Correct Answer: d) Iterators and references
Explanation:
Reallocation can move the character storage.
Correct Answer: a) Yes
Explanation:
std::string can copy from a null-terminated pointer.
Correct Answer: b) aaaaa
Explanation:
The fill constructor creates five copies of a.
Correct Answer: c) 3
Explanation:
The constructor creates three characters.
Correct Answer: d) Yes, using push_back or append
Explanation:
Strings support character and string appending.
Correct Answer: a) insert()
Explanation:
insert places new characters at a position.
Correct Answer: b) erase(pos, count)
Explanation:
erase deletes a range starting at pos.
Correct Answer: c) find_first_of()
Explanation:
find_first_of searches forward for matching characters.
Correct Answer: d) find_last_of()
Explanation:
find_last_of searches backward for matching characters.
Correct Answer: a) find_first_not_of()
Explanation:
It locates characters outside the specified set.
Correct Answer: b) find_last_not_of()
Explanation:
It searches backward for a character outside the set.
Correct Answer: c) A new std::string
Explanation:
substr creates a copied substring.
Correct Answer: d) Replaces a range with new contents
Explanation:
replace modifies a selected character range.
Correct Answer: a) 0
Explanation:
Zero indicates equality in comparison.
Correct Answer: b) true
Explanation:
empty is true when size is zero.
Correct Answer: c) It is undefined behavior
Explanation:
front requires a non-empty string.
Correct Answer: d) It is undefined behavior
Explanation:
back requires a non-empty string.
Correct Answer: a) Throws out_of_range
Explanation:
at performs bounds checking.
Correct Answer: b) operator[]
Explanation:
operator[] is unchecked for performance.
Correct Answer: c) c_str()
Explanation:
c_str returns a null-terminated character array.
Correct Answer: d) data()
Explanation:
Non-const data provides direct access to storage.
Correct Answer: a) Yes
Explanation:
The stored size includes embedded nulls.
Correct Answer: b) They stop at it
Explanation:
C-string APIs use null as the terminator.
Correct Answer: c) Lexicographical order
Explanation:
Relational operators compare character sequences.
Correct Answer: d) swap member or std::swap
Explanation:
swap exchanges contents efficiently.
Correct Answer: a) std::stoi
Explanation:
stoi parses integer text.
Correct Answer: b) std::stod
Explanation:
stod parses floating-point text.
Correct Answer: c) std::to_string
Explanation:
to_string creates text from numeric values.
Correct Answer: d) invalid_argument
Explanation:
invalid_argument indicates unparsable input.
Correct Answer: a) out_of_range
Explanation:
out_of_range indicates overflow or underflow.
Correct Answer: b) <string_view>
Explanation:
string_view is declared in its own header.
Correct Answer: c) Dangling if the underlying data is destroyed
Explanation:
string_view does not extend lifetime.
Correct Answer: d) Yes
Explanation:
A non-const string can be modified.
Correct Answer: a) Its contents cannot be modified
Explanation:
const prevents modification.
Correct Answer: b) Yes
Explanation:
std::string provides begin and end.
Correct Answer: c) Yes, since C++11
Explanation:
Characters are stored contiguously.
Correct Answer: d) Yes
Explanation:
std::string is a template with an allocator parameter.
Correct Answer: a) Characters excluding a terminating null
Explanation:
size reflects logical character count.
Correct Answer: b) Characters
Explanation:
length is equivalent to size.
Correct Answer: c) rfind()
Explanation:
rfind searches backward for a substring.
Correct Answer: d) std::string_view
Explanation:
string_view is designed for non-owning views.
Related Posts
NewNewNew
No Image
Latest C++ Functions MCQs
1. Which header is commonly used for std::string? a) <string> b) <iostream> c) <vector> d) <cstring> Show Answer Correct Answer:…
October 20, 2026By MCQs Generator
No Image
C++ Arrays / Lists - MCQs
1. Which header is commonly used for std::string? a) <string> b) <iostream> c) <vector> d) <cstring> Show Answer Correct Answer:…
October 20, 2026By MCQs Generator

C++ OOP MCQs Object-Oriented Programming
Object-Oriented Programming (OOP) in C++ revolutionizes software design by organizing code around data (objects) rather than relying solely on functions…
October 20, 2026By MCQs Generator








