C语言基本数据类型

C语言基本数据类型

类型

C语言规范

gcc-7.4.0 x86_64 (Bytes)

char

一个字节

1

short

字节数小于或等于int

2

int

 

4

long

字节数大于或者等于int

8

long long (C99)

字节数大于或者等于long

8

float

至少6位有效数字,且取值范围至少10-37 ~ 1037

4

double

至少10位有效数字,取值范围同float

8

long double (C99)

有效数字大于或等于double

16

说明:

1、对于整型,如果数据类型前没有unsigned修饰编译器按有符 号数据处理,如果前面有unsigned修饰则按无符号处理。

2、浮点型的数据类型不能用unsigned修饰。

3、浮点数和浮点数或者浮点数和整数都不能用“==”判断相等,应该看两数的差值是否在一个可接受的范围。比如:fabs(a - b) < 0.001

 

#include <stdio.h>

int main(void)
{
    printf("%-11s  %-6s  %s\n", "Type", "Length", "Unit");
    printf("%-11s  %-6ld  %s\n", "char", sizeof(char), "Bytes");
    printf("%-11s  %-6ld  %s\n", "short", sizeof(short), "Bytes");
    printf("%-11s  %-6ld  %s\n", "int", sizeof(int), "Bytes");
    printf("%-11s  %-6ld  %s\n", "long", sizeof(long), "Bytes");
    printf("%-11s  %-6ld  %s\n", "long long", sizeof(long long), "Bytes");
    printf("%-11s  %-6ld  %s\n", "float", sizeof(float), "Bytes");
    printf("%-11s  %-6ld  %s\n", "double", sizeof(double), "Bytes");
    printf("%-11s  %-6ld  %s\n", "long double", sizeof(long double), "Bytes");
	
	return 0;
}

输出(gcc-7.4.0 x86_64):

Type         Length  Unit
char         1       Bytes
short        2       Bytes
int          4       Bytes
long         8       Bytes
long long    8       Bytes
float        4       Bytes
double       8       Bytes
long double  16      Bytes

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值