← 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;
}
- A.8 +
- B.9 C
- C.9 +
- 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 →