- 山海与妖灵新手攻略 山海与妖灵攻略大全
- 2024-12-26 10:30:56
- 食之契约新手攻略 食之契约新手攻略大全
- 2024-12-26 10:15:59
- 《白蛇传奇:阵法与万剑归宗的获取》
- 2024-12-26 10:01:05
- 怒火合击《狂暴传奇》英雄合击详解及技能介绍
- 2024-12-26 09:46:21
- 《传奇霸主》卡位刷怪秘籍:快速清怪不是梦
- 2024-12-26 09:31:26
- 《传奇霸主》元宝使用秘籍:合理规划助你称霸江湖!
- 2024-12-26 09:16:16
对于c语言来说,数据类型是一个很重要的概念和知识点,它涉及到的是内存的空间,这在和硬件交互的时候是非常重要的。
K&R给出了7个数据类型相关的关键字,分别是:int、long、short、unsigned、char、float、double。后来C90增加了2个关键字,分别是:signed、void。再后来,C99又增加了3个关键字,分别是:_Bool、_Complex、_Imaginary。
整体来说,我们可以分为2个系列:分别是整数类型和浮点数类型。
下面就依次来说说了(环境:win7 64bit 、VS2015):
printf("int:bytes %d;bit %d\n", sizeof(int), sizeof(int) * 8);
int:bytes 4;bit 32
printf("int:MIN %d;MAX %d\n", INT_MIN, INT_MAX);
int:MIN -2147483648;MAX 2147483647 即-2^31~2^31-1
printf("unsigned int:bytes %d;bit %d\n", sizeof(unsigned int), sizeof(unsigned int) * 8);
unsigned int:bytes 4;bit 32
printf("unsigned int:MIN is 0;MAX %u\n", UINT_MAX);
unsigned int:MIN is 0;MAX 4294967295 即0~2^32
printf("char:bytes %d;bit %d\n", sizeof(char), sizeof(char) * 8);
char:bytes 1;bit 8
printf("char:MIN %d;MAX %d\n", CHAR_MIN, CHAR_MAX);
char:MIN -128;MAX 127 即-2^7~2^7-1
printf("unsigned char:bytes %d;bit %d\n", sizeof(unsigned char), sizeof(unsigned char) * 8);
unsigned char:bytes 1;bit 8
printf("unsigned char:MIN is 0;MAX %d\n", UCHAR_MAX);
unsigned char:MIN is 0;MAX 255 即0~2^8-1
printf("short:bytes %d;bit %d\n", sizeof(short), sizeof(short) * 8);
short:() 2;bit 16
printf("short :MIN %hd;MAX %hd\n", SHRT_MIN, SHRT_MAX);
short :MIN -32768;MAX 32767 即-2^15~2^15-1
printf("unsigned short:bytes %d;bit %d\n", sizeof(unsigned short), sizeof(unsigned short) * 8);
unsigned short:bytes 2;bit 16:bytes 2;bit 16
printf("unsigned short:MIN is 0;MAX %d\n", USHRT_MAX);
unsigned short:MIN is 0;MAX 65535 即0~2^16-1
printf("long:bytes %d;bit %d\n", sizeof(long), sizeof(long) * 8);
long:bytes 4;bit 32
printf("long :MIN %ld;MAX %ld\n", LONG_MIN, LONG_MAX);
long :MIN -2147483648;MAX 2147483647 即-2^31~2^31-1
unsigned long:bytes %d;bit %d\n", sizeof(unsigned long), sizeof(unsigned long) * 8);
unsigned long:bytes 4;bit 32
printf("unsigned long:MIN is 0;MAX %lu\n", ULONG_MAX);
unsigned long:MIN is 0;MAX 4294967295 即0~2^32-1
printf("long long :bytes %d;bit %d\n", sizeof(long long), sizeof(long long) * 8);
long long :bytes 8;bit 64
printf("long long :MIN %lld;MAX %llu\n", LLONG_MIN, LLONG_MAX);
long long :MIN -9223372036854775808;MAX 9223372036854775807 即-2^63~2^63-1
printf("unsigned long long:bytes %d;bit %d\n", sizeof(unsigned long long), sizeof(unsigned long long) * 8);
unsigned long long:bytes 8;bit 64
printf("unsigned long long:MIN is 0;MAX %llu\n", ULLONG_MAX);
unsigned long long:MIN is 0;MAX 18446744073709551615 即0~2^64-1
printf("float :bytes %d;bit %d\n", sizeof(float), sizeof(float) * 8);
float :bytes 4;bit 32
诸如:22.333444这样的数。其中8bit用于表示指数及其符号,24bit表示尾数或有效数字及其符号。
printf("float :bytes %d;bit %d\n", sizeof(float), sizeof(float) * 8);
double :bytes 8;bit 64
printf("long double :bytes %d;bit %d\n", sizeof(long double), sizeof(long double) * 8);
long double :bytes 8;bit 64
取值范围:理论上是比double有更高的精度,但是c只保证long double至少同double 一样的精度
#include <stdio.h> #include<limits.h> int main() { printf("int:bytes %d;bit %d\n", sizeof(int), sizeof(int) * 8); //int:bytes 4;bit 32 printf("int:MIN %d;MAX %d\n", INT_MIN, INT_MAX); // int:MIN -2147483648;MAX 2147483647 printf("unsigned int:bytes %d;bit %d\n", sizeof(unsigned int), sizeof(unsigned int) * 8); //unsigned int:bytes 4;bit 32 printf("unsigned int:MIN is 0;MAX %u\n", UINT_MAX); //unsigned int:MIN is 0;MAX 4294967295 printf("-------------------------------------------------------\n"); printf("char:bytes %d;bit %d\n", sizeof(char), sizeof(char) * 8); // char:bytes 1;bit 8 printf("char:MIN %d;MAX %d\n", CHAR_MIN, CHAR_MAX); // char:MIN -128;MAX 127 printf("unsigned char:bytes %d;bit %d\n", sizeof(unsigned char), sizeof(unsigned char) * 8); //unsigned char:bytes 1;bit 8 printf("unsigned char:MIN is 0;MAX %d\n", UCHAR_MAX); // unsigned char:MIN is 0;MAX 255 printf("-------------------------------------------------------\n"); printf("short:bytes %d;bit %d\n", sizeof(short), sizeof(short) * 8); // short:bytes 2;bit 16 printf("short :MIN %hd;MAX %hd\n", SHRT_MIN, SHRT_MAX); // short :MIN -32768;MAX 32767 printf("unsigned short:bytes %d;bit %d\n", sizeof(unsigned short), sizeof(unsigned short) * 8); //unsigned short:bytes 2;bit 16 printf("unsigned short:MIN is 0;MAX %d\n", USHRT_MAX); // unsigned short:MIN is 0;MAX 65535 printf("-------------------------------------------------------\n"); printf("long:bytes %d;bit %d\n", sizeof(long), sizeof(long) * 8); // long:bytes 4;bit 32 printf("long :MIN %ld;MAX %ld\n", LONG_MIN, LONG_MAX); // long :MIN -2147483648;MAX 2147483647 printf("unsigned long:bytes %d;bit %d\n", sizeof(unsigned long), sizeof(unsigned long) * 8); //unsigned long:bytes 4;bit 32 printf("unsigned long:MIN is 0;MAX %lu\n", ULONG_MAX); // unsigned long:MIN is 0;MAX 4294967295 printf("-------------------------------------------------------\n"); printf("long long :bytes %d;bit %d\n", sizeof(long long), sizeof(long long) * 8); // long long :bytes 8;bit 64 printf("long long :MIN %lld;MAX %llu\n", LLONG_MIN, LLONG_MAX); // long long :MIN -9223372036854775808;MAX 9223372036854775807 printf("unsigned long long:bytes %d;bit %d\n", sizeof(unsigned long long), sizeof(unsigned long long) * 8); //unsigned long long:bytes 8;bit 64 printf("unsigned long long:MIN is 0;MAX %llu\n", ULLONG_MAX); // unsigned long long:MIN is 0;MAX 18446744073709551615 printf("-------------------------------------------------------\n"); printf("float :bytes %d;bit %d\n", sizeof(float), sizeof(float) * 8); // float :bytes 4;bit 32 printf("double :bytes %d;bit %d\n", sizeof(double), sizeof(double) * 8); // double :bytes 8;bit 64 printf("long double :bytes %d;bit %d\n", sizeof(long double), sizeof(long double) * 8); // long double :bytes 8;bit 64 printf("-------------------------------------------------------\n"); return 0; }
网站内容来自网络,如有侵权请联系我们,立即删除!
Copyright © 大拿百科 鲁ICP备2024053388号-1