Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. struct A{
  7. int a;
  8. char b[10];
  9. };
  10.  
  11. struct B{
  12. int ba;
  13. int bb;
  14. };
  15.  
  16. int main(){
  17. B tmp;
  18. tmp.ba = 50;
  19. tmp.bb = 24;
  20. cout << tmp.ba << tmp.bb << "n";
  21.  
  22. // everything is fine yet
  23.  
  24. A obj;
  25. memcpy(&obj, &tmp, sizeof(tmp));
  26.  
  27. // 1. is this valid?
  28. cout << obj.a << "n";
  29.  
  30. B newB;
  31. memcpy(&newB, &obj, sizeof(newB));
  32.  
  33. // 2. Are these valid?
  34. cout << newB.ba << newB.bb << "n";
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement