🎙 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 6 of 10

What does this print? (code)

What does this print?

#include <iostream>
#include <string>
using namespace std;
int main() {
    string s = "Hello";
    s += " C++";
    cout << s.length() << " " << s[6] << "\n";
    return 0;
}
  1. A.8 +
  2. B.9 C
  3. C.9 +
  4. D.10 C
Answer & explanation

Correct answer: 9 C

"Hello C++" has 9 characters, and index 6 (counting from 0) is 'C'.

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 →