fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct s1
  6. {
  7. int i;
  8. float f;
  9. char c;
  10. };
  11.  
  12. struct s2
  13. {
  14. short s;
  15. float f;
  16. char c;
  17. };
  18.  
  19. struct s3
  20. {
  21. int i;
  22. double d;
  23. char c;
  24. };
  25.  
  26. int main()
  27. {
  28. cout << "s1::i: " << offsetof(s1, i) << endl;
  29. cout << "s1::f: " << offsetof(s1, f) << endl;
  30. cout << "s1::c: " << offsetof(s1, c) << endl << endl;
  31.  
  32. cout << "s2::s: " << offsetof(s2, s) << endl;
  33. cout << "s2::f: " << offsetof(s2, f) << endl;
  34. cout << "s2::c: " << offsetof(s2, c) << endl << endl;
  35.  
  36. cout << "s3::i: " << offsetof(s3, i) << endl;
  37. cout << "s3::d: " << offsetof(s3, d) << endl;
  38. cout << "s3::c: " << offsetof(s3, c) << endl << endl;
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
s1::i: 0
s1::f: 4
s1::c: 8

s2::s: 0
s2::f: 4
s2::c: 8

s3::i: 0
s3::d: 8
s3::c: 16