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

Quiz: C++ Introduction · Question 3 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, 4);
    return 0;
}
  1. A.lace
  2. B.acem
  3. C.plac
  4. D.cement
Answer & explanation

Correct answer: acem

substr(start, length): from index 2, take 4 characters → "acem".

Can you get the rest right without peeking?

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

Start the quiz →