int a = 2;//32位整数 4字节 4byte 32bit
unsigned int b = 2u;//无符号32位整数 4字节 4byte 32bit
signed int b1 = -2147483648;//有符号32位整数 4字节 4byte 32bit
long c = 2l;//32位整数 4字节 4byte 32bit
unsigned long d= 2ul;//无符号32位整数 4字节 4byte 32bit
double e = 2.0;//双精度浮点数
float f = 2.0f;//单精度浮点数
long double g=2.0l;//长双精度浮点数
long long h=2ll;//超长整数 64位整数 8字节 8byte 64bit
short i = 2;//16位整数 2字节 2byte 16bit
unsigned short i1 = 2;//无符号16位整数 2字节 2byte 16bit
char j = '2';//字符类型 1字节 1byte 8bit
char j1 = '2';//无符号字符类型 1字节 1byte 8bit
取类型值范围
std::cout <<"int a is :"<< a << " int类型取值范围:" <<INT_MIN <<","<<INT_MAX <<"\n"
<<"signed int b1 is :"<< b1 << " int类型取值范围: " <<INT_MIN <<","<<INT_MAX <<"\n"
<<"unsigned int b is : "<<b << " unsigned int类型取值范围: " <<0 <<","<<UINT_MAX <<"\n"
<<"long c is : "<<c<<" long类型取值范围: " <<LONG_MIN <<","<<LONG_MAX <<"\n"
<<"unsigned long d is : "<<d<<" unsigned long类型取值范围: " <<0 <<","<<ULONG_MAX <<"\n"
<<"double e is : "<<e<< " double类型取值范围:" <<DBL_MIN <<","<<DBL_MAX <<"\n"
<<"float f is : "<<f<<" float类型取值范围:" <<FLT_MIN <<","<<FLT_MAX <<"\n"
<<"long double g is : "<<g<<" long double类型取值范围:" <<LDBL_MIN <<","<<LDBL_MAX <<"\n"
<<"long long h is : "<<h<<" long long类型取值范围: " <<LLONG_MIN <<","<<LLONG_MAX <<"\n"
<<"short i is : "<<i<<" short类型取值范围: " <<SHRT_MIN <<","<<SHRT_MAX <<"\n"
<<"unsigned short i is : "<<i1<<" unsigned short类型取值范围: " <<0 <<","<<USHRT_MAX <<"\n"
<<"char j is : "<<j<<" char类型取值范围: " <<CHAR_MIN <<","<<CHAR_MAX <<"\n"
<<"unsigned char j1 is : "<<j1<<" unsigned char类型取值范围: " <<0 <<","<<UCHAR_MAX <<"\n";
输出效果:
int a is :2 int类型取值范围:-2147483648,2147483647 signed int b1 is :-2147483648 int类型取值范围: -2147483648,2147483647 unsigned int b is : 2 unsigned int类型取值范围: 0,4294967295 long c is : 2 long类型取值范围: -9223372036854775808,9223372036854775807 unsigned long d is : 2 unsigned long类型取值范围: 0,18446744073709551615 double e is : 2 double类型取值范围:2.22507e-308,1.79769e+308 float f is : 2 float类型取值范围:1.17549e-38,3.40282e+38 long double g is : 2 long double类型取值范围:3.3621e-4932,1.18973e+4932 long long h is : 2 long long类型取值范围: -9223372036854775808,9223372036854775807 short i is : 2 short类型取值范围: -32768,32767 unsigned short i is : 2 unsigned short类型取值范围: 0,65535 char j is : 2 char类型取值范围: -128,127 unsigned char j1 is : 2 unsigned char类型取值范围: 0,255
#include <iostream>
#include <chrono>
#include <thread>
#include <limits>
#include <float.h>
int main() {
int a = 2;//32位整数 4字节 4byte 32bit
unsigned int b = 2u;//无符号32位整数 4字节 4byte 32bit
signed int b1 = -2147483648;//有符号32位整数 4字节 4byte 32bit
long c = 2l;//32位整数 4字节 4byte 32bit
unsigned long d= 2ul;//无符号32位整数 4字节 4byte 32bit
double e = 2.0;//双精度浮点数
float f = 2.0f;//单精度浮点数
long double g=2.0l;//长双精度浮点数
long long h=2ll;//超长整数 64位整数 8字节 8byte 64bit
short i = 2;//16位整数 2字节 2byte 16bit
unsigned short i1 = 2;//无符号16位整数 2字节 2byte 16bit
char j = '2';//字符类型 1字节 1byte 8bit
char j1 = '2';//无符号字符类型 1字节 1byte 8bit
//进度表示写法
int bin2 =0b11111111;//二进制 0和1 前缀:0b stdc++ 14
int bin8 = 077;//八进制 0~7 前缀:0
int bin16= 0xff;//十六进制 0~F 前缀:0x
int aa = INT_MAX * 2 + 1;
unsigned int bb = UINT_MAX;
if (aa == bb)
std::cout<<UINT_MAX<<std::endl;
std::cout <<"int a is :"<< a << " int类型取值范围:" <<INT_MIN <<","<<INT_MAX <<"\n"
<<"signed int b1 is :"<< b1 << " int类型取值范围: " <<INT_MIN <<","<<INT_MAX <<"\n"
<<"unsigned int b is : "<<b << " unsigned int类型取值范围: " <<0 <<","<<UINT_MAX <<"\n"
<<"long c is : "<<c<<" long类型取值范围: " <<LONG_MIN <<","<<LONG_MAX <<"\n"
<<"unsigned long d is : "<<d<<" unsigned long类型取值范围: " <<0 <<","<<ULONG_MAX <<"\n"
<<"double e is : "<<e<< " double类型取值范围:" <<DBL_MIN <<","<<DBL_MAX <<"\n"
<<"float f is : "<<f<<" float类型取值范围:" <<FLT_MIN <<","<<FLT_MAX <<"\n"
<<"long double g is : "<<g<<" long double类型取值范围:" <<LDBL_MIN <<","<<LDBL_MAX <<"\n"
<<"long long h is : "<<h<<" long long类型取值范围: " <<LLONG_MIN <<","<<LLONG_MAX <<"\n"
<<"short i is : "<<i<<" short类型取值范围: " <<SHRT_MIN <<","<<SHRT_MAX <<"\n"
<<"unsigned short i is : "<<i1<<" unsigned short类型取值范围: " <<0 <<","<<USHRT_MAX <<"\n"
<<"char j is : "<<j<<" char类型取值范围: " <<CHAR_MIN <<","<<CHAR_MAX <<"\n"
<<"unsigned char j1 is : "<<j1<<" unsigned char类型取值范围: " <<0 <<","<<UCHAR_MAX <<"\n";
std::cout<<"二进制0b11111111值是:"<<bin2<<std::endl;
std::cout<<"八进制077值是:"<<bin8<<std::endl;
std::cout<<"十六进制0xff值是:"<<bin16<<std::endl;
std::cout << "等待5秒后退出程序" <<std::endl;
std::this_thread::sleep_for(std::chrono::seconds(5));
return 0;