fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct S1{
  5. int a; int b; int c; int d;
  6. };
  7.  
  8. struct S2{
  9. int a; int b;
  10. };
  11.  
  12. int main() {
  13. S1 obj1;
  14. obj1.a = 1;
  15. obj1.b = 2;
  16. obj1.c = 3;
  17. obj1.d = 4;
  18.  
  19. cout << obj1.a << " "
  20. << obj1.b << " "
  21. << obj1.c << " "
  22. << obj1.d << "\n";
  23.  
  24. auto ptr = reinterpret_cast<S2 *>(&obj1);
  25.  
  26. cout << ptr->a << " " << ptr->b << "\n";
  27.  
  28. // someFunc(ptr, sizeof(obj1));
  29. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1 2 3 4
1 2