Question 18
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
#include <string>
using namespace std::string_literals;
int main() {
auto a = "Hi"s + " there";
auto b = "Hi" " there";
std::cout << a << '|' << b << '|' << a.size() << '|' << sizeof(b) << '\n';
return 0;
}
- A Hi there|Hi there|8|8 Correct
- B Hi there|Hi there|8|9
- C Hi there|Hi|8|8
- D Hi there|Hi there|9|9
Correct Answer: Option A
"Hi"s is a std::string, so + works. Adjacent literals are joined by the compiler; but b is declared with auto from an array, so it decays to const char*, and sizeof(b) is the pointer size, 8.
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!