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;
    }
  • 相关阅读:
    枚举定义三个常量--遍历如下
    初始化和赋值的概念
    javascript 事件
    HTML 5 本地存储
    html5 说明
    JQuery 双击动态编辑
    ThinkPHP 3.2.2 事务
    PHP AJAX JSONP实现跨域请求使用实例
    chorme 插件
    frontend-tools
  • 原文地址:https://www.cnblogs.com/tszr/p/10968680.html
Copyright © 2011-2022 走看看