Q:

What does the following program do? Is it valid? If not, why not?

0

What does the following program do? Is it valid? If not, why not?

string s;
cout << s[0] << endl;

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
#include <string>

int main() {
  std::string s;
  std::cout << s[0] << std::endl;  // The subscript is out of range, result is undefined.

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now