【C++ 学习笔记小程序05】 const限定符 浮点数 算数运算符
来源:互联网 发布:高新广电网络客服电话 编辑:程序博客网 时间:2024/05/29 18:16
#include "MyFirstDemo.h"#include <iostream>#include <climits>// 引入资源包using namespace std;MyFirstDemo::MyFirstDemo(void){}MyFirstDemo::~MyFirstDemo(void){} // 声明函数原型 void my_const();void my_float();void my_arithmetic();int main(){// 调用自定义函数 <pre name="code" class="cpp"> <span style="white-space:pre"></span>my_const();<span style="white-space:pre"></span>my_float();<span style="white-space:pre"></span>my_arithmetic();// 在windows平台,某些编译器会在程序执行完之后关闭窗口,这样就看不到输出// 以下代码读取下一次键击,这样就可以看到输出,按“enter” 程序继续执行cin.get();cin.get();cin.get();return 0;} // 20141126 const限定符void my_const(){// 0 、 个人觉得和Java中的final语句差不多// 1 、 常常用来定义常量,声明后需要立即初始化。编译器将不允许修改该值const int MOUTH = 10;} // 浮点数void my_float(){// 0 、 浮点数的由来// 浮点数被分为两个部分存储;一部分是数据,另一部分是对值得缩放因子。例如10.01;被分为0.1001和10两部分;// 因子控制小数点的位移,浮点数由此得名// 浮点数类型// floatfloat f = 2.2555f;// doubledouble d = 2.3333333333333;// long doublelong double ld = 2.33333333335555; // 浮点数的优缺点:可以表示证书之间的值;可以表示更大的范围;运算数度比正数慢,并且计算精度会降低;float a = 2.34E+22f;float b = a + 1.0f;cout << "a is : " << a << endl;cout << "b is : " << b << endl;cout << "b - a is : " << b - a << endl; // 输出0}// 算数运算符void my_arithmetic(){// 0 、 + 、 - 、 * 、 / 、 % 五种// 加int int_a = 5 + 6;int int_b = 5;int int_c = 6;int int_d = int_b + int_c;// 减float f_a = 5 - 2.01f;float f_b = 5.0;float f_c = 6.0;float f_d = f_b - f_c;// 乘int int_e = 5 * 3;float f_e = 5 * 3.0;int int_f = int_b * int_c;// 除int int_g = 5/3;float f_g = 5.0/3.0;// 模(取余)int int_h = 5%3;// 1 、 优先级*/%大于+-// 2 、 操作符重载的例子(先前提到<<的重载)// 除法符号/的重载:除法到底输出整型还是浮点型,由除数和被除数决定;两者都是整形是,输出整型,其他情况都是输出浮点数;}
0 0
- 【C++ 学习笔记小程序05】 const限定符 浮点数 算数运算符
- const限定符学习笔记
- C++primer学习笔记-----4.2算数运算符
- C++Primer学习笔记—(const限定符)
- c++primer学习笔记-----2.4const限定符
- 学习笔记:C++primer 2.4 const限定符
- c++primer笔记--2.4const限定符
- c++-const限定符
- C++const限定符
- C++const限定符
- java学习笔记(算数运算符 赋值运算符 )
- C++primer :const限定符
- 2.C++--const限定符
- 【从C到C++学习笔记】bool类型/const限定符/#define//结构体对齐
- C++Primer学习札记_指针和const限定符
- c++学习笔记-指针和const限定符
- c++学习笔记--指针和const限定符
- C++中关于const限定符学习笔记
- 《网络协议》TCP/IP 基本概述
- struts2怎样做支持json
- hdu-2152 Fruit
- 分类、扩展和协议
- 算法:动态规划
- 【C++ 学习笔记小程序05】 const限定符 浮点数 算数运算符
- 二分图最大匹配
- BIRT没有类似Excel的格式刷,其他免费报表有么?
- JUnit简单教程
- Ubuntu 12.04更新源
- 函数指针相关知识
- SetStreamSource的解惑
- bzoj 3620: 似乎在梦中见过的样子
- Android Studio 快捷键