C语言各类型在x86与x64环境下的长度

    xiaoxiao2021-04-17  33

    struct T { char a; int b; char c; }; struct E { }; // Linux 平台 (基于 CentOS6.5) printf("%d\n", sizeof(struct T)); //x86 12 x64 12 printf("%d\n", sizeof(struct E)); //x86 0 x64 0 printf("%d\n", sizeof(char)); //x86 1 x64 1 printf("%d\n", sizeof(short int)); //x86 2 x64 2 printf("%d\n", sizeof(int)); //x86 4 x64 4 printf("%d\n", sizeof(long)); //x86 4 x64 8 printf("%d\n", sizeof(long long)); //x86 8 x64 8 printf("%d\n", sizeof(float)); //x86 4 x64 4 printf("%d\n", sizeof(double)); //x86 8 x64 8 printf("%d\n", sizeof(long double)); //x86 12 x64 16 printf("%d\n", sizeof(void)); //x86 1 x64 1 printf("%d\n", sizeof(void*)); //x86 4 x64 8 printf("%d\n", sizeof(size_t)); //x86 4 x64 8 // Windows 平台 (基于 VS2013 Win10) printf("%d\n", sizeof(struct T)); //x86 12 x64 12 printf("%d\n", sizeof(struct E)); //x86 1 x64 1 printf("%d\n", sizeof(short int)); //x86 2 x64 2 printf("%d\n", sizeof(int)); //x86 4 x64 4 printf("%d\n", sizeof(long)); //x86 4 x64 4 printf("%d\n", sizeof(long long)); //x86 8 x64 8 printf("%d\n", sizeof(float)); //x86 4 x64 4 printf("%d\n", sizeof(double)); //x86 8 x64 8 printf("%d\n", sizeof(long double)); //x86 8 x64 8 //printf("%d\n", sizeof(void)); //error C2070 printf("%d\n", sizeof(void*)); //x86 4 x64 8 printf("%d\n", sizeof(size_t)); //x86 4 x64 8 类型Linux x86Linux x64Win x86Win x64struct T12121212struct E0011char1111short int2222int4444long4844long long8888float4444double8888long double121688void11--void*4848size_t4848
    类型formatchar%csigned char%c (or %hhi for numerical output)unsigned char%c (or %hhu for numerical output)shortshort intsigned shortsigned short int%hiunsigned shortunsigned short int%huintsignedsigned int%i or %dunsignedunsigned int%ulonglong intsigned longsigned long int%li or %ldunsigned longunsigned long int%lulong longlong long intsigned long longsigned long long int%lli or %lldunsigned long longunsigned long long int%llufloat%f (promoted automatically to double for printf())double%f (%F)(%lf (%lF) for scanf())%g %G%e %Elong double%Lf %LF%Lg %LG%Le %LE
    转载请注明原文地址: https://ju.6miu.com/read-673651.html

    最新回复(0)