fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct test
  5. {
  6. char a, b, c, d;
  7. };
  8.  
  9. int main() {
  10.  
  11. char memory[] = {'a', 'b', 'c', 'd'};
  12. test t{};
  13. cout << "Before: " << t.a << t.b << t.c << t.d << endl;
  14. t = *(test *)&memory;
  15. cout << "After: " << t.a << t.b << t.c << t.d << endl;
  16. return 0;
  17. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Before: 
After: abcd