C++-基础笔记2
运算
算术运算
-用处 单独放在一个操作符前面 表示正负号反转
赋值运算
a = a + 5 等效于 a+=5
类型转换
C++转换示例
1 | double d; |
常见数学函数
先引入头文件#include <cmath>
或者#include <math.h>
返回的类型 函数名(参数的类型) //例如乘方函数
double pow(double,double)//第一个参数底数,第二个参数指数
float pow(float,float)//函数名相同但类型不同,称之为函数重载
1 | cout << pow(2,3) << endl; //乘方 |
注意
同是int类型得到结果会舍去小数部分 例如 1 / 2 得到结果 0
应用 1.0 / 2 = 0.5 使用浮点数得到结果
逻辑相关运算
见C基础笔记
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Frite的个人博客!