zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然C语言开发:位域

    struct
    {
      unsigned int widthValidated;
      unsigned int heightValidated;
    } status;
    struct
    {
      unsigned int widthValidated : 1;
      unsigned int heightValidated : 1;
    } status;
    #include <stdio.h>
    #include <string.h>
     
    /* 定义简单的结构 */
    struct
    {
      unsigned int widthValidated;
      unsigned int heightValidated;
    } status1;
     
    /* 定义位域结构 */
    struct
    {
      unsigned int widthValidated : 1;
      unsigned int heightValidated : 1;
    } status2;
     
    int main( )
    {
       printf( "Memory size occupied by status1 : %d
    ", sizeof(status1));
       printf( "Memory size occupied by status2 : %d
    ", sizeof(status2));
     
       return 0;
    }
    struct
    {
      unsigned int age : 3;
    } Age;
    #include <stdio.h>
    #include <string.h>
     
    struct
    {
      unsigned int age : 3;
    } Age;
     
    int main( )
    {
       Age.age = 4;
       printf( "Sizeof( Age ) : %d
    ", sizeof(Age) );
       printf( "Age.age : %d
    ", Age.age );
     
       Age.age = 7;
       printf( "Age.age : %d
    ", Age.age );
     
       Age.age = 8; // 二进制表示为 1000 有四位,超出
       printf( "Age.age : %d
    ", Age.age );
     
       return 0;
    }
  • 相关阅读:
    数据库创建用户SQL
    团队总结和展示
    第十三周总结
    梦断代码02
    第十二周进度博客
    团队冲刺第十五天
    团队冲刺第十四天
    团队冲刺第一阶段评价
    梦断代码01
    第十一周进度博客
  • 原文地址:https://www.cnblogs.com/tszr/p/10968680.html
Copyright © 2011-2022 走看看