0
点赞
收藏
分享

微信扫一扫

【C语言】整数及浮点数据类型

老罗话编程 2022-03-20 阅读 35
c语言
类型字节大小值范围
char1-128 ~ 127
unsigned char10 ~ 255
short2-32768 ~ 32767
unsigned short20 ~ 65535
int4-2147483648 ~ 2147483647
unsigned int40 ~ 4294967295
long4-2147483648 ~ 2147483647
unsigned long40 ~ 4294967295
long long8-9223372036854775808 ~ 9223372036854775807
unsigned long long80 ~ 18446744073709551615
类型字节大小值范围精度有效位数
float41.175494E-038 ~ 3.402823E+0386
double82.225074E-308 ~1.797693E+30815
long double163.172905E-317 ~ 3.172897E-31718

测试代码

#include <stdio.h>
#include <limits.h>
#include <float.h>



int main()
{
    printf("char  占用字节%d  值范围 %d - %u\n", sizeof(char), CHAR_MIN, CHAR_MAX);
    printf("unsigned char  占用字节%d  值范围 %d - %u\n\n", sizeof(unsigned char), 0, UCHAR_MAX);

    printf("short  占用字节%d  值范围 %d - %u\n", sizeof(short), SHRT_MIN, SHRT_MAX);
    printf("unsigned short  占用字节%d  值范围 %d - %u\n\n", sizeof(unsigned short), 0, USHRT_MAX);

    printf("int  占用字节%d  值范围 %d - %u\n", sizeof(int), INT_MIN, INT_MAX);
    printf("unsigned int  占用字节%d  值范围 %d - %u\n\n", sizeof(unsigned int), 0, UINT_MAX);

    printf("long  占用字节%d  值范围 %d - %u\n", sizeof(long), LONG_MIN, LONG_MAX);
    printf("unsigned long  占用字节%d  值范围 %d - %lu\n\n", sizeof(unsigned long), 0, ULONG_MAX);

    printf("long long  占用字节%d  值范围 %lld - %llu\n", sizeof(long long), LLONG_MIN, LLONG_MAX);
    printf("unsigned long long  占用字节%d  值范围 %d - %llu\n\n", sizeof(unsigned long long), 0, ULLONG_MAX);

    printf("float  占用字节%d  值范围 %E - %E  精度为%d\n", sizeof(float), FLT_MIN, FLT_MAX, FLT_DIG);
    printf("double  占用字节%d  值范围 %E - %E  精度为%d\n", sizeof(double), DBL_MIN, DBL_MAX, DBL_DIG);
    printf("long double  占用字节%d  值范围 %E - %E  精度为%d\n\n", sizeof(long double), LDBL_MIN, LDBL_MAX, LDBL_DIG);

}

举报

相关推荐

浮点数类型的判断

0 条评论