C++ Primer Plus (第六版)之旅 第三章01
来源:互联网 发布:nginx重定向域名不变 编辑:程序博客网 时间:2024/05/18 01:57
1.变量从何而来(存储信息的三个特性)
有点类型名字从何而来
---信息存储在哪里
---存储什么值
---存储何种类型的信息
2.C++变量命名规则
a) 名称只能使用字母、数字、下划线
b) 名称第一个不能是数字
c) 注意了,分区大小写
d) 不要用C++关键字!!!!
e) 我自己认为,变量名要通俗易懂,不要乱起,别整个goudan啥的,虽然C++对变量名字没有限制,但是别太长了,不然多丑啊
自己最好去练习,其实吧,你写错了,编都编不过地!!!
3.整形 short、int、long、longlong
普及知识:1字节=8位,1KB=1024字节,1MB=1024KB
计算机最基本组成单元就是位
至于类型和字节数介绍我用例子来征服你吧!!!
<span style="font-size:18px;">#include<iostream> #include<string> #include <limits> using namespace std; int main() { cout << "type: \t\t" << "************size**************"<< endl; cout << "bool: \t\t" << "所占字节数:" << sizeof(bool); cout << "\t最大值:" << (numeric_limits<bool>::max)(); cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl; cout << "char: \t\t" << "所占字节数:" << sizeof(char); cout << "\t最大值:" << (numeric_limits<char>::max)(); cout << "\t\t最小值:" << (numeric_limits<char>::min)() << endl; cout << "signed char: \t" << "所占字节数:" << sizeof(signed char); cout << "\t最大值:" << (numeric_limits<signed char>::max)(); cout << "\t\t最小值:" << (numeric_limits<signed char>::min)() << endl; cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char); cout << "\t最大值:" << (numeric_limits<unsigned char>::max)(); cout << "\t\t最小值:" << (numeric_limits<unsigned char>::min)() << endl; cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t); cout << "\t最大值:" << (numeric_limits<wchar_t>::max)(); cout << "\t\t最小值:" << (numeric_limits<wchar_t>::min)() << endl; cout << "short: \t\t" << "所占字节数:" << sizeof(short); cout << "\t最大值:" << (numeric_limits<short>::max)(); cout << "\t\t最小值:" << (numeric_limits<short>::min)() << endl; cout << "int: \t\t" << "所占字节数:" << sizeof(int); cout << "\t最大值:" << (numeric_limits<int>::max)(); cout << "\t最小值:" << (numeric_limits<int>::min)() << endl; cout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned); cout << "\t最大值:" << (numeric_limits<unsigned>::max)(); cout << "\t最小值:" << (numeric_limits<unsigned>::min)() << endl; cout << "long: \t\t" << "所占字节数:" << sizeof(long); cout << "\t最大值:" << (numeric_limits<long>::max)(); cout << "\t最小值:" << (numeric_limits<long>::min)() << endl; cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long); cout << "\t最大值:" << (numeric_limits<unsigned long>::max)(); cout << "\t最小值:" << (numeric_limits<unsigned long>::min)() << endl; cout << "double: \t" << "所占字节数:" << sizeof(double); cout << "\t最大值:" << (numeric_limits<double>::max)(); cout << "\t最小值:" << (numeric_limits<double>::min)() << endl; cout << "long double: \t" << "所占字节数:" << sizeof(long double); cout << "\t最大值:" << (numeric_limits<long double>::max)(); cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl; cout << "float: \t\t" << "所占字节数:" << sizeof(float); cout << "\t最大值:" << (numeric_limits<float>::max)(); cout << "\t最小值:" << (numeric_limits<float>::min)() << endl; cout << "size_t: \t" << "所占字节数:" << sizeof(size_t); cout << "\t最大值:" << (numeric_limits<size_t>::max)(); cout << "\t最小值:" << (numeric_limits<size_t>::min)() << endl; cout << "string: \t" << "所占字节数:" << sizeof(string) << endl; // << "\t最大值:" << (numeric_limits<string>::max)() << "\t最小值:" << (numeric_limits<string>::min)() << endl; cout << "type: \t\t" << "************size**************"<< endl; return 0; } </span>
你也可以去 climits这个文件里看看有一些 宏定义的,定义了一些值的范围
咳咳,有点累了,大家也早睡吧~~~~,有问题大家可以留言
0 0
- C++ Primer Plus (第六版)之旅 第三章01
- 《C Primer Plus 》第六版 习题 第三章
- C++Primer Plus(第六版) 第六章 第二题
- C++Primer Plus(第六版) 第七章 第六题
- C++ Primer Plus (第六版)之旅 第二章
- C++ Primer Plus(第六版)--学习杂记(第三章)
- c++ Primer Plus(第六版)第三章习题,写代码之路
- C++Primer Plus(第六版) 第八章 第二题
- C++Primer Plus(第六版) 第八章 第四题
- C++Primer Plus(第六版) 第十章 第八题
- C Primer Plus(第6版)第六章答案
- C++Primer Plus(第六版) 第十一章 第七题
- C++Primer Plus(第六版) 第十二章 第一题
- C++Primer Plus(第六版) 第十二章 第二题
- C++Primer Plus(第六版) 第十三章 第一题
- C++Primer Plus(第六版) 第十三章 第二题
- C++Primer Plus(第六版) 第十三章 第四题
- C++Primer Plus(第六版) 第十四章 第一题
- 数组元素出现次数统计
- hdu4725The Shortest Path in Nya Graph---spfa求最短路
- HBase介绍
- 数据可视化---之---数据色彩化
- JAVA设计模式--观察者
- C++ Primer Plus (第六版)之旅 第三章01
- linux-cp(转)
- mysql5.7以上解压版安装
- 完全二叉树的三种遍历
- C语言中将二维数组作为参数传递给函数的方法
- Morse Code-神奇而朴实的摩斯电码
- java内部类的可见性总结和java内部类的创建
- 构造函数的具体使用
- 拉格朗日乘数法解带约束的极值问题