🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Strings in C++: all 10 questions

Quiz: Strings in C++ · Question 1 of 10

What does this print? (code)

What does this print?

#include <iostream>
#include <string>
using namespace std;
int main() {
    string s = "placement";
    cout << s.substr(2, 3);
    return 0;
}
  1. A.ac
  2. B.ace
  3. C.acem
  4. D.lac
Answer & explanation

Correct answer: ace

substr(2, 3) starts at index 2 ('a') and takes 3 characters: "ace".

Can you get the rest right without peeking?

Take the timed Quiz: Strings in C++ quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →