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