← 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;
}
- A.lace
- B.acem
- C.plac
- 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 →