整型变量表示整数类型的数字类型,比如-2, -1, 0 , 1, 2, 3
数据类型 | 内存空间 | 数据范围 |
---|---|---|
char(最小整型) | 1个字节 | -128 ~ 127, (-2^7 ~ 2^7-1) |
uchar(非负数字符型) | 1个字节 | 0 ~ 255, (2^8-1) |
short (短整型) | 2个字节 | -32768 ~ 32767, (-2^15 ~ 2^15-1) |
ushort (非负数短整型) | 2个字节 | 0 ~ 65535, (2^16-1) |
int (整型) | 4个字节 | - 2,147,483,648 ~ 2,147,483,647, (-2^31 ~ 2^31-1) |
uint (非负数整型) | 4个字节 | 0 ~ 4,294,967,295 (2^32-1) |
long(长整型) | 8个字节 | -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (-2^63 ~ 2^63-1) |
ulong(非负数长整型) | 8个字节 | 0 ~ 18,446,744,073,709,551,615, (2^64-1) |
void OnStart()
{
// 1.最小整型
char c1 = -128; // -128 ~ 127
uchar c2= 255; // 0 ~ 255
// 2.短整型
short s1 = -32768; // -32768 ~ 32767
ushort s2 = 65535; // 0 ~65535
// 3.整型
int a = 2100000000; // -21亿 ~ 21亿
uint b = 4100000000; // 0 ~ 42亿
// 4.长整型 -922亿亿 到 922亿亿
long l1 = -4100000000000;
ulong l2 = 8100000000000;
// 5.数据超出范围的情况
int i1 = 2147483647;
printf("i1的值: %d", i1);
int i2 = 2147483649; // 2147483649 - 2147483647 = 2 + -2147483648
printf("i2的值: %d", i2);
}