Advertisement
avr39ripe

cppStructPadding

Jun 2nd, 2021
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. struct Test
  4. {
  5.     bool f1; // 1
  6.     double f2; // 8
  7.     int f3; // 4
  8. }; //13
  9.  
  10. //[b][ ][ ][ ][ ][ ][ ][ ]
  11. //[d][d][d][d][d][d][d][d]
  12. //[i][i][i][i][ ][ ][ ][ ]
  13.  
  14.  
  15. struct Test1
  16. {
  17.     bool f1; // 1
  18.     int f3; // 4
  19.     double f2; // 8
  20. }; //13
  21.  
  22. //[b][ ][ ][ ][i][i][i][i]
  23. //[d][d][d][d][d][d][d][d]
  24.  
  25.  
  26. // [0][1][2][3] [4][5][6][7] [8][9][10][11]
  27. // [b][d][d][d] [d][d][d][d] [d][i][i ][i ]
  28. // [i ][ ][ ][ ] [ ][ ][ ][ ] [ ][ ][  ][  ]
  29.  
  30.  
  31.  
  32. int main()
  33. {
  34.     std::cout << "bool - > " << sizeof(bool) << '\n';
  35.     std::cout << "double - > " << sizeof(double) << '\n';
  36.     std::cout << "int - > " << sizeof(int) << '\n';
  37.     std::cout << "Test - > " << sizeof(Test) << '\n';
  38.     std::cout << "Test1 - > " << sizeof(Test1) << '\n';
  39.     return 0;
  40. }
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement