zoukankan      html  css  js  c++  java
  • c语言中输出int型在内存中的占位

    c语言中输出不同数据类型在内存中的占位

    1、

    #include <stdio.h>
    
    int main(void)
    {
        int n = 0;
        unsigned x = ~0U;
        while(x)
        {
            if(x & 1U)
                n++;
            x >>= 1;
        }
        printf("the number of bits: %u
    ", n);
        return 0;
    }

    2、

    #include <stdio.h>
    
    int main(void)
    {
        int bits = 0;
        unsigned x = ~(0 & 1);
        while(x)
        {
            if(x & 1U)
                bits++;
            x >>= 1;
        }
        
        printf("the result:   %u
    ", bits);
        return 0;
    }

    3、

    #include <stdio.h>
    
    int main(void)
    {
        int bits = 0;
        unsigned long x = ~0U;
        while(x)
        {
            if(x & 1U)
                bits++;
            x >>= 1;
        }
        
        printf("the result:   %d
    ", bits);
        return 0;
    }

    4、

    #include <stdio.h>
    
    int main(void)
    {
        int bits = 0;
        unsigned long x = ~(0 & 5);
        while(x)
        {
            if(x & 1U)
                bits++;
            x >>= 1;
        }
        
        printf("the result:   %d
    ", bits);
        return 0;
    }

  • 相关阅读:
    菜根谭#317
    菜根谭#316
    菜根谭#315
    菜根谭#314
    菜根谭#313
    菜根谭#312
    菜根谭#311
    菜根谭#310
    菜根谭#309
    Matlab xpC启动盘
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14791985.html
Copyright © 2011-2022 走看看