Question 3
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
#include <string>
int main() {
std::string s = "programming";
std::cout << s.substr(3) << ' ' << s.substr(0, 3) << ' ' << s.substr(3, 4) << ' ' << s.substr(8, 100) << '\n';
return 0;
}
- A gramming pro gram ing Correct
- B gramming pro gra ing
- C ramming pro gram ing
- D gramming prog gram ing
Correct Answer: Option A
substr(pos) takes the rest; substr(pos, n) takes n characters; a count past the end is simply clipped.
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!