zoukankan      html  css  js  c++  java
  • 测试机器上各数据类型占用的字节数

    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    void testTypeSize()
    {
    	int bool_len = sizeof(bool);
    	int char_len = sizeof(char);
    	int short_len = sizeof(short);
    	int int_len = sizeof(int);
    	int long_len = sizeof(long);
    	int longlong_len = sizeof(long long);
    	int float_len = sizeof(float);
    	int double_len = sizeof(double);
    	printf("bool: %d bytes
    ", bool_len);
    	printf("char: %d bytes
    ", char_len);
    	printf("short: %d bytes
    ", short_len);
    	printf("int: %d bytes
    ", int_len);
    	printf("long: %d bytes
    ", long_len);
    	printf("long long: %d bytes
    ", longlong_len);
    	printf("float: %d bytes
    ", float_len);
    	printf("double: %d bytes
    ", double_len);
    }
    
    int main()
    {
    	testTypeSize();
    	return 0;
    }
    

    输出如下(仅以我的air13pro为例):

  • 相关阅读:
    递归
    排序算法的稳定性与复杂度总结
    二分查找
    希尔排序
    快速排序
    归并排序
    插入排序
    选择排序
    冒泡排序
    i2c_smbs 函数
  • 原文地址:https://www.cnblogs.com/xzxl/p/8621785.html
Copyright © 2011-2022 走看看