fork download
  1. #include <iostream>
  2. using namespace std;
  3. struct QQ
  4. {
  5. short b = 7788;
  6. //2 byte padding.
  7. int a = 5566;
  8.  
  9. };
  10. int main() {
  11. cout<<sizeof(QQ)<<endl;
  12.  
  13. QQ q;
  14. cout<<"&q.a = "<<&q.a<<endl;
  15. cout<<"&q.b = "<<&q.b<<endl;
  16. cout<<"delta: "<<(char*)&q.a - (char*)&q.b<<endl;
  17. short* ptr = (short*)&q;
  18. ptr++;
  19. //ptr++;
  20. cout<<*((int*)ptr)<<endl;
  21. return 0;
  22. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
8
&q.a = 0xff836e7c
&q.b = 0xff836e78
delta: 4
364838787