Question 6
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 a = "car", b = "cart", c = "Car";
std::cout << (a < b) << (c < a) << (a == "car") << ("100" < std::string("99")) << (b.compare(a) > 0) << '\n';
return 0;
}
- A 11111 Correct
- B 10111
- C 11101
- D 01111
Correct Answer: Option A
A prefix is smaller ("car" < "cart"); 'C' < 'c'; equal contents compare equal; '1' < '9' decides "100" < "99"; and b is greater than a, so compare returns a positive value.
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!