Question 10
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <algorithm>
#include <iostream>
#include <string>
int main() {
std::string s = "stream";
std::string r(s.rbegin(), s.rend());
std::sort(s.begin(), s.end());
std::cout << r << ' ' << s << '\n';
return 0;
}
- A maerts aemrst Correct
- B maerts stream
- C stream aemrst
- D maerts tsrmea
Correct Answer: Option A
Constructing a string from reverse iterators makes a reversed copy. Sorting arranges the characters by code: a e m r s t.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!