fork download
  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. struct Target {
  5. char foo[8];
  6. };
  7.  
  8. struct Trap {
  9. unsigned i1, i2;
  10. };
  11.  
  12. int main() {
  13. Target t;
  14. strcpy(t.foo, "AAAAAAA");
  15.  
  16. Trap* tr = reinterpret_cast<Trap*>(&t);
  17.  
  18. fprintf(stdout, "Before: %s\n", t.foo);
  19. printf("%x %x\n", tr->i1, tr->i2);
  20.  
  21. tr->i1 = 0x42424242;
  22. tr->i2 = 0x00424242;
  23.  
  24. printf("After: %s\n", t.foo);
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Before: AAAAAAA
41414141 414141
After: BBBBBBB