数据类型
  C

数据类型

 次点击
12 分钟阅读

整型

编号

数据类型

字节

取值范围

1

char

1

-128~127

2

unsigned shar

1

0~255

3

short

2

-32768~32767

4

unsigned short

2

0~65535

5

int

4

-2147483648~2147483647

6

unsigned int

4

0 ~ 4294967295

7

long

4(32位系统)、8(64位系统)

8

unsigned long

4(8)

9

long long

8

-9223372036854775808 ~ 9223372036854775807

10

unsigned long long

8

0-18446744073709551615

/usr/include/limits.h文件中,有数据类型范围的定义

//查看各数据类型的范围
#include<stdio.h>
#include<limits.h>

int main(){
	printf("char:%d~%d\n",SCHAR_MIN,SCHAR_MAX);
	printf("short:%d~%d\n",SHRT_MIN,SHRT_MAX);
	printf("int:%d~%d\n",INT_MIN,INT_MAX);
	printf("long:%ld~%ld\n",LONG_MIN,LONG_MAX);
	return 0;
}

sizeof是C语言中的保留关键字,也是单目运算符。能获取某个数据类型所占空间的字节数
使用方法:sizeof(变量名称)或者sizeof 变量名称 或者 sizeof(数据类型)

int a;
sizeof(a) //建议
sizeof a  //可行
sizeof(int)//建议
sizeof int //不可行
//sizeof使用示例
#include <stdio.h>
int main()
{
	printf("sizeof(char)=%lu\n", sizeof(char));
	printf("sizeof(short)=%lu\n", sizeof(short));
	printf("sizeof(int)=%lu\n", sizeof(int));
	printf("sizeof(long)=%lu\n", sizeof(long));
	printf("sizeof(long long)=%lu\n", sizeof(long long));
	return 0;
}

© 本文著作权归作者所有,未经许可不得转载使用。