#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <iostream>
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 = %d\n",I_MAX);
printf("I_MIN = %d\n",I_MIN);
//ok
printf("L_MAX = %lld\n",L_MAX);
printf("L_MIN = %lld\n",L_MIN);
//error
printf("TEST_L_MAX = %lld\n",TEST_L_MAX);
printf("TEST_L_MIN = %lld\n",TEST_L_MIN);
printf("sizeof(unsigned long long) = %d\n",sizeof(unsigned long long));
printf("sizeof(unsigned long) = %d\n",sizeof(unsigned long));
printf("sizeof(long) = %d\n",sizeof(long));
cout << endl;
printf("INT_MAX = %d\n",INT_MAX);
printf("INT_MIN = %d\n",INT_MIN);
printf("LONG_MAX = %ld\n",LONG_MAX);
printf("LONG_MIN = %ld\n",LONG_MIN);
printf("LLONG_MAX = %ld\n",LLONG_MAX);
printf("LLONG_MIN = %ld\n",LLONG_MIN);
while(*str >= '0' && *str <= '9'){
ret = ret*10 + (*str - '0');
str++;
}
printf("ret = %ld\n",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位)