易百教程

变量类型和值范围

变量类型和典型值范围,如下表中所示:

类型 典型字节数 典型的值范围
char 1 -128 ~ +1270 ~ +255
unsigned char 1 0 ~ +255
short 2 -32,768 ~ +32,767
unsigned short 2 0 ~ +65,535
int 2 或 4 -32,768 ~ +32,767-2,147,438,648 ~ +2,147,438,647
unsigned int 4 0 ~ +65,5350 ~ +4,294,967,295
long 4 -2,147,438,648 ~ +2,147,438,647
unsigned long 4 0 ~ +4,294,967,295
long long 8 -9,223,372,036,854,775,808 ~ +9,223,372,036,854,775,807
unsigned long long 8 0 ~ +18,446,744,073,709,551,615
float 4 +/-3.4E+/-38 (6位数)
double 8 +/-1.7E+/-308 (15位数)
long double 12 +/-1.2E+/-4932(19位数)