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

What does this print? (code)

What does this print?

#include <iostream>
#include <sstream>
using namespace std;
int main() {
    stringstream ss("4 5 x 6");
    int v, sum = 0;
    while (ss >> v) sum += v;
    cout << sum;
    return 0;
}
  1. A.15
  2. B.9
  3. C.4
  4. D.0
Answer & explanation

Correct answer: 9

Reading stops at "x" because it is not a number, so only 4 + 5 are added.

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 →