C/C++ | 各类型精度 |(int,char,float,double,long long int等)

速查表:

char             -128 ~ +127        (1 Byte)    
short             -32767 ~ + 32768    (2 Bytes)   3*10^4
unsigned short     0 ~ 65536        (2 Bytes)    6*10^4
int             -2147483648 ~ +2147483647   (4 Bytes)    2*10^9
unsigned int         0 ~ 4294967295    (4 Bytes)       4*10^9
long == int
long long         -9223372036854775808 ~ +9223372036854775807    (8 Bytes)      9*10^18
double         1.7 * 10^308        (8 Bytes)


符号属性 长度属性 基本型 所占位数 取值范围 输入符举例 输出符举例

    -- -- char                            8 -2^7 ~ 2^7-1 %c %c、%d、%u
    
    signed -- char                    8 -2^7 ~ 2^7-1 %c %c、%d、%u
    
    unsigned -- char                8 0 ~ 2^8-1 %c %c、%d、%u
    
    [signed] short [int]            16 -2^15 ~ 2^15-1 %hd
    
    unsigned short [int]           16 0 ~ 2^16-1 %hu、%ho、%hx
    
    [signed] -- int                    32 -2^31 ~ 2^31-1 %d
    
    unsigned -- [int]                 32 0 ~ 2^32-1 %u、%o、%x
    
    [signed] long [int]              32 -2^31 ~ 2^31-1 %ld
    
    unsigned long [int]             32 0 ~ 2^32-1 %lu、%lo、%lx
    
    [signed] long long [int]       64 -2^63 ~ 2^63-1 %I64d
    
    unsigned long long [int]      64 0 ~ 2^64-1 %I64u、%I64o、%I64x
    
    -- -- float                            32 +/- 3.40282e+038 %f、%e、%g
    
    -- -- double                        64 +/- 1.79769e+308 %lf、%le、%lg %f、%e、%g
    
    -- long double                    96 +/- 1.79769e+308 %Lf、%Le、%Lg

注意:

浮点参数压栈的规则:float(4 字节)类型扩展成double(8 字节)入栈。

  所以在输入时,需要区分float(%f)与double(%lf),而在输出时,用%f即可。
    
    printf函数将按照double型的规则对压入堆栈的float(已扩展成double)和double型数据进行输出。
    
    如果在输出时指定%lf格式符,gcc/mingw32编译器将给出一个警告。

猜你喜欢

转载自blog.csdn.net/stone_fall/article/details/88562972