标签:include pac ret div nbsp hex 输出 ace short
#include <bits/stdc++.h> using namespace std; struct B { B() { this->chr = 0xcccc; } short chr; }; struct A { B s; int i; }; int main() { int64_t i64 = 0x1234567890abcedfll; A *a = reinterpret_cast<A*>(&i64); cout << hex << a->s.chr << "," << a->i << "," << i64 << endl; int64_t i642 = 0x0; A b(*a); cout << hex << setw(4) << b.s.chr << "," << b.i << "," << *reinterpret_cast<int64_t*>(&b) << endl; return 0; }
输出结果为:
cedf,12345678,1234567890abcedf cedf,12345678,1234567890abcedf
如果修改为:
struct B { B(const B&) { this->chr = 0xcedf; } short chr; };
则结果为:
cedf,12345678,1234567890abcedf cedf,12345678,123456780000cedf
标签:include pac ret div nbsp hex 输出 ace short
原文地址:https://www.cnblogs.com/rongminglu/p/12923967.html