Members a and b were fully constructed, so they are destroyed in reverse order; c failed and d was never started; Owner's body and destructor never run.
What is the output of the following C++ program on a 64-bit system?
main.cpp
#include <iostream>
#include <stdexcept>
#include <string>
int main() {
int sum = 0;
for (std::string s : {"12", "7abc", "x9", "99999999999", " 4"}) {
try { sum += std::stoi(s); }
catch (const std::invalid_argument&) { std::cout << "invalid "; }
catch (const std::out_of_range&) { std::cout << "range "; }
}
std::cout << sum << '\n';
return 0;
}
Ainvalid range 23
Binvalid invalid range invalid 12
Cinvalid range 19
Dinvalid invalid range 16
Correct Answer: Option A
stoi reads leading digits ("7abc" gives 7) and skips leading spaces (" 4" gives 4). Only "x9" has no number, and 99999999999 does not fit an int: 12 + 7 + 4 = 23.
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·