Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- struct A{
- int a;
- char b[10];
- };
- struct B{
- int ba;
- int bb;
- };
- int main(){
- B tmp;
- tmp.ba = 50;
- tmp.bb = 24;
- cout << tmp.ba << tmp.bb << "n";
- // everything is fine yet
- A obj;
- memcpy(&obj, &tmp, sizeof(tmp));
- // 1. is this valid?
- cout << obj.a << "n";
- B newB;
- memcpy(&newB, &obj, sizeof(newB));
- // 2. Are these valid?
- cout << newB.ba << newB.bb << "n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement