标签:利用 limt eof src 浮点 linu min com 技术
代码如下:
#include<stdio.h>
#include<climits>
#include<limits.h>
//利用标准头文件<limts.h>来确定个类型数据的范围,但是浮点型的范围不能用这种方法表示出来
int main() {
//signed types
printf("signed char min=%d\n", SCHAR_MIN);//-2^7
printf("signed char max=%d\n", SCHAR_MAX);//2^7-1
printf("signed short min=%d\n", SHRT_MIN);//-2^15
printf("signed short max=%d\n", SHRT_MAX);//2^15-1
printf("signed int min=%d\n", INT_MIN);//-2^31
printf("signed int max=%d\n", INT_MAX);//2^31-1
printf("signed long min=%ld\n", LONG_MIN);//-2^31
printf("signed long max=%ld\n", LONG_MAX);//2^31-1
//unsigned types(最小值就是0)
printf("unsigned char max=%u\n", UCHAR_MAX);//2^8-1
printf("unsigned short max=%u\n", USHRT_MAX);//2^16-1
printf("unsigned int max=%u\n", UINT_MAX);//2^32-1
printf("unsigned long max=%lu\n", ULONG_MAX);//2^32-1
printf("%zd\t%zd\n", sizeof(unsigned int), sizeof(signed int));
//4,4
//说明有无unsigned只会影响其所能容纳的数据的阈值,而其所占内存不变
printf("%zd\t%zd\t%zd\t%zd\n",sizeof(char), sizeof(short), sizeof(int), sizeof(long));
//1,2,4,4
printf("%zd\t%zd\t%zd\n", sizeof(long long), sizeof(float), sizeof(double));
//8,4,8
//故char类型占1个字节,short类型占2个字节,int类型占4个字节
//long类型:64位Windows中占4个字节,64位linux中占8个字节
//long long类型占8个字节,float类型占4个字节,double类型占8个字节
}
运行结果如下:
只有char与short、char与char、short与short之间的运算都是先将其转换为int型,再进行运算。而其他的情况都是先将其向容量大(能够表示数的范围)的一种类型转换,然后再进行运算的
代码如下:
#include<stdio.h>
int main(void) {
char charType = ‘a‘;
short shortType = 1;
int intType = 2;
long long longlongType = 3;
float floatType = 4.0;
double doubleType = 5.0;
//先将其转换为int,再进行运算
printf("%zd\t%zd\t%zd\n", sizeof(charType + charType), sizeof(charType + shortType), sizeof(shortType + shortType));
//int + longlong,则先将int转化为8个字节的longlong,再运算
printf("%zd\t%zd\t%zd\n", sizeof(intType + intType), sizeof(intType + longlongType), sizeof(longlongType + longlongType));
//float的表示范围比int要大(至于为何,比较复杂,此处不赘述,需要的可自行百度),故先将其转换为float,再运算
printf("%zd\t%zd\t%zd\n", sizeof(intType + floatType), sizeof(intType + doubleType), sizeof(floatType + doubleType));
//float的表示范围比longlong要大(原因同上),故先将其转换为float,再运算
printf("%zd\n", sizeof(longlongType + floatType));
}
运行结果如下:
标签:利用 limt eof src 浮点 linu min com 技术
原文地址:https://www.cnblogs.com/young12123/p/14256952.html