#include<iostream>
using namespace std;
int main(){
//负数
int test = -1;
cout<<test<<endl;
//sizeof
cout<<"size of int is "<<sizeof(test)<<endl;
//MAX and MIN
cout<<"INT_MAX = "<<INT_MAX<<endl;//符号常量 可以查询各个类型的最大最小值
cout<<"INT_MIN = "<<INT_MIN<<endl;
cout<<"CHAR_MAX = "<<CHAR_MAX<<endl;
cout<<"CHAR_MIN = "<<CHAR_MIN<<endl;
//不会为负的数
unsigned int positive = 0;
positive = -1;
cout<<"define a unsigned int and assign it as -1, it will be "<<positive<<endl;
//浮点数
cout<<"direct cout 10/3 = "<<10/3<<endl;
float f = 10/3;//float 可表示数据中的前六个或七个有效位
cout<<"float cout 10/3 = "<<f<<endl;
double d = 10/3;
cout<<"double cout 10/3 = "<<d<<endl;
cout<<"direct cout 10.0/3.0 = "<<10.0/3.0<<endl;
f = 10.0/3.0;
cout<<"float cout 10.0/3.0 = "<<f<<endl;
d = 10.0/3.0;
cout<<"double cout 10.0/3.0 = "<<d<<endl;
cout<<"direct cout 10/3.0 = "<<10/3.0<<endl;
cout<<"direct cout 10.0/3 = "<<10.0/3<<endl;
cout<<"(float)10/(float)3 = "<<(float)10/(float)3<<endl;
//算术运算
cout<<"25/13 = "<<25/13<<endl;//小数部分被丢弃,而非四舍五入
cout<<"25.0/13.0 = "<<25.0/13.0<<endl;
return 0;
}
C++ Premier Plus丨笔记丨第三章
最新推荐文章于 2023-05-24 21:57:47 发布
本文深入探讨了C++中的基本数据类型,包括整型(如INT_MAX和INT_MIN)、字符型(CHAR_MAX和CHAR_MIN)以及无符号整型在赋负数时的行为。此外,还详细解释了浮点数(float和double)的表示精度问题,并通过示例展示了不同类型之间的算术运算,如除法运算中的取整规则。
摘要由CSDN通过智能技术生成