#include#include #include #include #include using namespace std; #define I_MAX (1<<31) -1 #define I_MIN -(1<<31) #define L_MAX (1ULL<<63) -1 #define L_MIN -(1ULL<<63) //1ULL、1UL、1L:如果不指定的话就是默认的int类型,所以int类型的范围(1<<31 -1)较小 #define TEST_L_MAX (1<<63) -1 #define TEST_L_MIN -(1<<63) int main(){ char *str = "23344232432342"; long long ret = 0; printf("I_MAX = %dn",I_MAX); printf("I_MIN = %dn",I_MIN); //ok printf("L_MAX = %lldn",L_MAX); printf("L_MIN = %lldn",L_MIN); //error printf("TEST_L_MAX = %lldn",TEST_L_MAX); printf("TEST_L_MIN = %lldn",TEST_L_MIN); printf("sizeof(unsigned long long) = %dn",sizeof(unsigned long long)); printf("sizeof(unsigned long) = %dn",sizeof(unsigned long)); printf("sizeof(long) = %dn",sizeof(long)); cout << endl; printf("INT_MAX = %dn",INT_MAX); printf("INT_MIN = %dn",INT_MIN); printf("LONG_MAX = %ldn",LONG_MAX); printf("LONG_MIN = %ldn",LONG_MIN); printf("LLONG_MAX = %ldn",LLONG_MAX); printf("LLONG_MIN = %ldn",LLONG_MIN); while(*str >= '0' && *str <= '9'){ ret = ret*10 + (*str - '0'); str++; } printf("ret = %ldn",ret); }
打印:
I_MAX = 2147483647 I_MIN = -2147483648 L_MAX = 9223372036854775807 L_MIN = -9223372036854775808 TEST_L_MAX = 4294967295 TEST_L_MIN = 0 sizeof(unsigned long long) = 8 sizeof(unsigned long) = 8 sizeof(long) = 8 INT_MAX = 2147483647 INT_MIN = -2147483648 LONG_MAX = 9223372036854775807 LONG_MIN = -9223372036854775808 LLONG_MAX = 9223372036854775807 LLONG_MIN = -9223372036854775808 ret = 23344232432342
注意:如果没有ULL/UL/L后缀,则系统默认为 int类型.
1ULL:表示1是unsigned long long 类型(64位系统占8byte,64位)
1UL:表示1是unsigned long 类型(64位系统占8byte,64位)
1L:表示1是long 类型(64位系统占8byte,64位)



