C++:数据类型
2024-10-20 05:37:39
/**
* C++ 数据类型 : https://www.runoob.com/cplusplus/cpp-data-types.html
*
* 布尔: bool
* 字符: char 1 个字节 -128 到 127 或者 0 到 255
* unsigned char 1 个字节 0 到 255
* signed char 1 个字节 -128 到 127
* 整型: int 4个字节 -2147483648 到 2147483647
* unsigned int 4 个字节 0 到 4294967295
* signed int 4个字节 -2147483648 到 2147483647
*
* short int 2 个字节 -32768 到 32767
* unsigned short int 2个字节 0 到 65,535
* signed short int 2个字节 -32768 到 32767
*
* long int 8 个字节 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807
* signed long int 8个字节 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807
* unsigned long int 8个字节 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807
*
* 浮点型: float 4 个字节 精度型占4个字节(32位)内存空间,+/- 3.4e +/- 38 (~7 个数字)
* 双浮点: double 8个字节 双精度型占8 个字节(64位)内存空间,+/- 1.7e +/- 308 (~15 个数字)
* long double 16 个字节 长双精度型 16 个字节(128位)内存空间,可提供18-19位有效数字。
* 无类型: void
* 宽字符: wchar_t 2 或 4 个字节 1 个宽字符
*/
#include <iostream>
#include <limits>
using namespace std;
int main(){
cout << "type: \t\t" << "*******size********" << endl; // endl 换行
// cout << "bool: \t\t" << "所占字节数: " << sizeof(bool) << endl; // sizeof 获取数据类型的大小
// cout << "\t最大值:" << (numeric_limits<bool>::max)(); // (numeric_limits<bool>::max)() 获取数据类型的最大值
// cout << "\t最小值: " << (numeric_limits<bool>::min)() << endl; // (numeric_limits<bool>::max)() 获取数据类型的最小值
// // char
// cout << "char: \t\t" << "所占字节数: " << sizeof(char) << endl; // sizeof 获取数据类型的大小
// cout << "\t最大值:" << (numeric_limits<char>::max)(); // (numeric_limits<bool>::max)() 获取数据类型的最大值
// cout << "\t最小值: " << (numeric_limits<char>::min)() << endl; // (numeric_limits<bool>::max)() 获取数据类型的最小值
// // signed char
// cout << "signed char: \t\t" << "所占字节数: " << sizeof(signed char) << endl; // sizeof 获取数据类型的大小
// cout << "\t最大值:" << (numeric_limits<signed char>::max)(); // (numeric_limits<bool>::max)() 获取数据类型的最大值
// cout << "\t最小值: " << (numeric_limits<signed char>::min)() << endl; // (numeric_limits<bool>::max)() 获取数据类型的最小值
// // unsigned char
// cout << "unisgned char: \t\t" << "所占字节数: " << sizeof(unsigned char) << endl;
// cout << "\t最大值: " << (numeric_limits<unsigned char>::max)();
// cout << "\t最小值: " << (numeric_limits<unsigned char>::min)() << endl;
// wchar_t
cout << "wchar_t: \t\t" << "所占字节数: " << sizeof(wchar_t) << endl;
cout << "\t最大值: " << (numeric_limits<wchar_t>::max)();
cout << "\t最小值: " << (numeric_limits<wchar_t>::min)() << endl;
// short
cout << "short: \t\t" << "所占字节数: " << sizeof(short) << endl;
cout << "\t最大值: " << (numeric_limits<short>::max)();
cout << "\t最小值: " << (numeric_limits<short>::min)() << endl;
// int
cout << "int: \t\t" << "所占字节数: " << sizeof(int) << endl;
cout << "\t最大值: " << (numeric_limits<int>::max)();
cout << "\t最小值: " << (numeric_limits<int>::min)() << endl;
// size_t
cout << "size_t: \t\t" << "所占字节数: " << sizeof(size_t) << endl;
cout << "\t最大值: " << (numeric_limits<size_t>::max)();
cout << "\t最小值: " << (numeric_limits<size_t>::min)() << endl;
// typedef : 为存在的 类型换个新名字
typedef int number; // typedef 已有类型 新名称;
number age; // 声明 number 类型 的变量 age
age = 18;
// typeid(age).name() 获取变量的数据类型
cout << "age: " << age << "类型: " << typeid(age).name() << endl;
// 枚举类型 enum
enum User{
name,
age1
} user;
user = name;
cout << "user: " << user << endl;
return 0;
}
最新文章
- Entity Framework 6 Recipes 2nd Edition(11-12)译 ->; 定义内置函数
- web响应式图片设计实现
- 动态页面 servlet
- ios 写项目的时候遇到的问题及解决方案(1)
- led显字风扇原理?
- json编解码
- phpStorm打开提示 failed to create JVM 的解决的方法
- 从Java熟练到Android入门
- ASP.NET Core Razor 视图组件
- Java 并发基础——线程安全性
- 15 Actionbar的显示和隐藏
- LBS(Location Based Service)(基于位置的服务)
- threejs深入纹理,立体场景cubeResolution(四)
- 10分钟开发 GPS 应用,了解一下
- 【Java深入研究】8、Java中Unsafe类详解
- Android FileUtils 文件操作类
- 延续(continuation)
- 64位系统VBS调用32位COM组件
- python numpy的transpose函数用法
- JSON初体验(三):FastJson解析
热门文章
- CodeGen编写自定义表达式标记
- pytest命令行参数
- UI自动化在RobotFramework中采用的分层设计
- Docker 版 3分钟部署 .net core 开源在线客服系统,他来了
- ElGamal算法
- Centos8.3、mysql8.0主从复制实战记录
- Java并发之ReentrantLock源码解析(一)
- 十八、.net core(.NET 6)搭建ElasticSearch(ES)系列之使用Logstash通过Rabbitmq接收Serilog日志到ES
- 怎样用好PS中的钢笔工具(附练习钢笔工具网站)
- Redis i/o timeout