zoukankan      html  css  js  c++  java
  • [C++] struct memory allocation

            MAX-byte alignment (最大单位对齐)

     1 typedef struct user  USER;
     2 typedef struct employee E;
     3 struct user{
     4 
     5     char name[10];  //take 12 bytes
     6     int age; //take 4 bytes
     7     short sex;//take 4 bytes
     8     char blood;//take 1 bytes but in  the 4 bytes of sex
     9 };
    10 struct employee{
    11 
    12     char name[5];  //take 8 bytes
    13     int age; //take 4 bytes
    14     char blood;//take 4 bytes 
    15 };
    16 int main(){
    17 
    18     printf("%d
    ", sizeof(USER));// 12+4+4
    19     printf("%d
    ", sizeof(E));// 8+4+4
    20     system("pause");
    21 }

     

  • 相关阅读:
    周总结
    周总结
    周总结
    读后感
    周总结
    周总结
    周总结
    第一周总结
    大学生失物招领平台使用体验
    快速乘法+快速幂
  • 原文地址:https://www.cnblogs.com/tianhangzhang/p/4872834.html
Copyright © 2011-2022 走看看