LearnFrenzy
Sign in Take a free test

std::string · Exercise 1 of 4

std::string std::string MCQ

  • 20 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on std::string: creation, concatenation, find and npos, substr, replace, erase, comparison, conversions, string_view and C++20/23 helpers. Pick an option to check your answer instantly.

Question 11 Medium

What does std::to_string(2.5) return?

A "2.5"
B "2.500000"
C "2"
D "2.50"
Question page & discussion
Question 12 Medium

Which statement about std::string_view is true?

A It copies the characters it is given
B It refers to characters owned by someone else, so the data must stay alive while the view is used
C It can modify the characters
D It always ends with '\0'
Question page & discussion
Question 13 Easy

Why would you call s.c_str()?

A To make a copy of s
B To get a const char* to a null-terminated buffer for C functions such as printf or fopen
C To convert s to lowercase
D To clear s
Question page & discussion
Question 14 Easy

Which C++20 call tests whether url begins with "https"?

A url.begins("https")
B url.starts_with("https")
C url.prefix("https")
D url.find("https") == 1
Question page & discussion
Question 15 Medium

With using namespace std::string_literals;, what is the type of "hi"s?

A const char*
B std::string
C std::string_view
D char[3]
Question page & discussion
Question 16 Easy

Given std::string s = "cat";, what does s[0] = 'b'; do?

A Compile error – strings are immutable
B Changes s to "bat"
C Creates a new string
D Undefined behaviour
Question page & discussion
Question 17 Easy

Which reads "New Delhi" completely into a std::string city?

A std::cin >> city;
B std::getline(std::cin, city);
C std::cin.get(city);
D city.read(std::cin);
Question page & discussion
Question 18 Medium

What does s.find_first_of("aeiou") return?

A The position of the substring "aeiou"
B The position of the first character in s that is any one of a, e, i, o, u
C The number of vowels
D true or false
Question page & discussion
Question 19 Hard

Given std::string s = "Code";, what does s += 65; do?

A Appends "65"
B Appends the character with code 65, 'A'
C Compile error
D Adds 65 to every character
Question page & discussion
Question 20 Easy

Which call reverses s in place?

A s.reverse();
B std::reverse(s.begin(), s.end());
C s = -s;
D std::reverse(s);
Question page & discussion
Up next · Exercise 2Predict the Output20 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links