forked from zhmzhen/candcppCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd.cpp
More file actions
18 lines (15 loc) · 1.9 KB
/
d.cpp
File metadata and controls
18 lines (15 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
std::string createString() {
std::string str = "Hello, World!01234567890 0123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890 0123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890 0123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890 0123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890 0123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890 0123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890 0123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890 0123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890 0123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890 0123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890 01234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890";
std::cout << "Address inside function: " << static_cast<void*>(&str) << std::endl;
std::cout << "Address inside function: data=" << static_cast<void*>(str.data()) << std::endl;
return str; // Copy elision happens here
}
int main() {
std::string result;
result = createString();
std::cout << "Address in main: " << static_cast<void*>(&result) << std::endl;
std::cout << "Address in main function: data=" << static_cast<void*>(result.data()) << std::endl;
return 0;
}