第三章:C++中的C

3.1创建函数:

  • 旧版本中的C,可以带任意个数和类型的参数调用函数,编译器都不会出错,缺乏对参数传递的协助以及会导致高深莫测的故障,所以当时被称为高级汇编语言。
  • 函数原型,用参数类型确保正确的处理返回值,传递参数。
  • 参数表中包含了应当传递给函数的参数类型和参数的标识符(对声明而言任选)
  • 参数的顺序和类型必须在声明,定义与函数调用中相匹配
  • 在C++中,函数定义可以用未命名的参数,当然,因为未命名,在函数体中无法使用,目的,为了将参数列表保留位置。
  • c中function()与c++中function()的区别。
  • 可变参数列表使用,

可以拒绝错误检查功能。

#include< iostream>
using namespace std;int add(int a, int b , ...)

{
return a + b ;
}

int main(){  int final = add(1.7,2.5,4);  cout<<final;  return 0;
}
3.1.1函数的返回值
  • C++中函数原型必须指明函数的返回类型(在C中,如果省略返回值,表示默认为整型)
  • 在一个函数定义中可以有多个return 语句
3.1.2使用C的函数库
  • 如果希望该应用程序具有可移植性,就应该限制使用编译器以自带非标准库函数。
  • 如果必须执行特定平台的活动,应当尽力把代码隔离在某一场所,以便移植到另一平台时容易进行修改.在C++中,经常把特定的活动封装在一个类中,这是一个理想的解决办法。
  • 包含头文件,调用函数
3.1.3通过库管理器创建自己的库
  • 如果想要创建一个库,那么就建立一个头文件,它包含库中的所有函数原型,把所有的对象模块联通建成后的库名传递给库管理器,将建成的库与其他库放在同一个位置,一边连接器能发现它
3.2一览
  • for(int i = 0 ; i < 10 ; i++ )是可以的。
  • 作用域。

3.4 数据类型简介

  • 数据类型定义使用存储空间(内存)的方式,通过定义数据类型,告诉编译器怎样创建一片特定的存储空间,以及怎样操纵这篇存储空间。
  • 内建数据类型是编译器本来能理解的数据类型,直接与编译器相关联
  • 用户定义的数据类型是我们与别的1程序员创建道德类型,作为一个类,一般被称为抽象数据类型。
3.4.1.基本内建类型
  • 标准C的内建类型规范不说明每一个内建类型必须有多少位,规范只规定内建类型必须能存储的最大值和最小值。
BCD
二进制编码的十进制(Binary-Coded Decimal)
- 机器基于二进制,则最大值可以直接转换为容纳这个值的所需的最少位数,若基于BCD,在机器中容纳每一种数据类型的最大数值的空间是不同的。详见< climits> 与< cfloat>
- the code
#include<iostream>
#include<string>
#include <limits>
using namespace std;int main()
{cout << "type: \t\t" << "************size**************" << endl;//about the boolcout << "bool: \t\t" << "所占字节数:" << sizeof(bool);cout << "\t最大值:" << (numeric_limits<bool>::max)();cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl;//about the charcout << "char: \t\t" << "所占字节数:" << sizeof(char);cout << "\t最大值:" << (numeric_limits<char>::max)();cout << "\t\t最小值:" << (numeric_limits<char>::min)() << endl;//about the signed charcout << "signed char: \t" << "所占字节数:" << sizeof(signed char);cout << "\t最大值:" << (numeric_limits<signed char>::max)();cout << "\t\t最小值:" << (numeric_limits<signed char>::min)() << endl;//about the unsigned charcout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char);cout << "\t最大值:" << (numeric_limits<unsigned char>::max)();cout << "\t\t最小值:" << (numeric_limits<unsigned char>::min)() << endl;//about the wchar_tcout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t);cout << "\t最大值:" << (numeric_limits<wchar_t>::max)();cout << "\t\t最小值:" << (numeric_limits<wchar_t>::min)() << endl;//about the shortcout << "short: \t\t" << "所占字节数:" << sizeof(short);cout << "\t最大值:" << (numeric_limits<short>::max)();cout << "\t\t最小值:" << (numeric_limits<short>::min)() << endl;//about the intcout << "int: \t\t" << "所占字节数:" << sizeof(int);cout << "\t最大值:" << (numeric_limits<int>::max)();cout << "\t最小值:" << (numeric_limits<int>::min)() << endl;//about the unsigned intcout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned);cout << "\t最大值:" << (numeric_limits<unsigned>::max)();cout << "\t最小值:" << (numeric_limits<unsigned>::min)() << endl;//about the longcout << "long: \t\t" << "所占字节数:" << sizeof(long);cout << "\t最大值:" << (numeric_limits<long>::max)();cout << "\t最小值:" << (numeric_limits<long>::min)() << endl;//about the unsigned longcout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long);cout << "\t最大值:" << (numeric_limits<unsigned long>::max)();cout << "\t最小值:" << (numeric_limits<unsigned long>::min)() << endl;//about the doublecout << "double: \t" << "所占字节数:" << sizeof(double);cout << "\t最大值:" << (numeric_limits<double>::max)();cout << "\t最小值:" << (numeric_limits<double>::min)() << endl;//about the long doublecout << "long double: \t" << "所占字节数:" << sizeof(long double);cout << "\t最大值:" << (numeric_limits<long double>::max)();cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl;//about the floatcout << "float: \t\t" << "所占字节数:" << sizeof(float);cout << "\t最大值:" << (numeric_limits<float>::max)();cout << "\t最小值:" << (numeric_limits<float>::min)() << endl;//about the size_tcout << "size_t: \t" << "所占字节数:" << sizeof(size_t);cout << "\t最大值:" << (numeric_limits<size_t>::max)();cout << "\t最小值:" << (numeric_limits<size_t>::min)() << endl;//about the stringcout << "string: \t" << "所占字节数:" << sizeof(string) << endl;// << "\t最大值:" << (numeric_limits<string>::max)() << "\t最小值:" << (numeric_limits<string>::min)() << endl;cout << "type: \t\t" << "************size**************" << endl;return 0;
}
  • the result
3.4.1bool类型与true 和false
元素 布尔类型的用法
&&,||,! 带布尔参数并产生bool结果
if,for,while,do 条件表达式转化为bool
>,<,<=,>=,==,!= 产生bool结果
?: 第一个操作数转化为bool

- 编译器隐式转换intbool

最新文章

  1. SQL Server 2008如何进行数据库同步?
  2. 《移动项目实践》实验报告——Android调试与上线
  3. 路径搜索 – Dijkstra 算法 (MATLAB实现)
  4. 英国出土1600年前的文物,上面居然刻着简体中文?!
  5. html5 微格式,HTML5 微格式和相关的属性名称
  6. java 对象列表_Java中的对象列表
  7. plSql安装以及连接远程oracle相关配置
  8. 修改js版本_啥都学点之使用nvm安装Node.js并实现Node.js多版本管理
  9. 【Linux】【Services】【Package】编译安装
  10. paip.提升用户体验---c++ QPushButton按钮控件透明以及不规则按钮以及 鼠标越过动态设置
  11. 关于IBM刀片服务器
  12. [转载]关于太阳(卫星)天顶角,太阳高度角,太阳方位角的整理_akala啦_新浪博客...
  13. 最详细的Pycharm使用技巧 2020.06.06
  14. C++ async future deferred
  15. 成长了,记录一下,增值税发票识别写入excel文件里
  16. 最长递增子序列O(NlogN)算法
  17. PuTTY基本使用,Linux基本命令
  18. css布局——GFC
  19. 移动Web MUI框架Switch开关自定义中文文字
  20. python登录网页后抓取数据_Python抓取网页数据的终极办法

热门文章

  1. Selenium 详解CSS定位
  2. 嵌入式开发学习之--点亮LED灯(上)
  3. android 六边形布局,纯CSS响应式六边形网格布局
  4. 高级软件架构师实战培训阶二
  5. 双11狂欢节模板 让大屏“闪电”起来
  6. Webots机器人仿真软件
  7. OpenCV实现动态人脸识别(第四讲)
  8. 如何把网站添加到手机主屏幕 website Add to Home Screen
  9. python基础教程pdf刘浪_《Python基础教程(第3版)》 PDF高清完整版_初学者如何学习Python...
  10. This class (or a class that this class inherits from) is marked as ‘@immutable‘