![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++随笔
___292
逆水行舟,不进则退~
展开
-
自增与解引用
++ 优先级大于 * ,离变量距离相同eg: *p++,指针自增其他情况,谁离变量近先算谁eg:*++p和++*p,前者指针自增,后者值自增```c++// *p++void test(){ cout << "_____*p++_____" << endl; int a[3] = {1,3,5}; int* p = a; cout << "*p : " << *p << endl; cout << .原创 2020-06-04 15:28:35 · 479 阅读 · 0 评论 -
const总结
constconst限定符:限制变量,使其值不能改变const对象仅在当前文件内有效,如果多文件共享const对象,加extern关键字const的引用:引用绑定到const对象上(常量引用)const指针:必须初始化,存放指针的地址无法改变(*const)顶层const:指针本身是常量(指向不可变,值可变)(作用于对象本身)底层const:指针指向是常量(指向可变,值不可变)常量表达式:值不会变且子啊编译过程就能计算结果的表达式。constexpr变量:由编译器来验证变原创 2020-06-03 23:29:47 · 90 阅读 · 0 评论 -
函数与指针
函数指针1. 函数指针的使用bool lengthCompare(const string& str1, const string& str2){ if (str1 == str2) return true; return false;}int main(){ /* 函数指针定义:函数类型(返回值类型和形参类型共同决定) 函数类型 bool(const string &...原创 2020-06-03 23:23:23 · 125 阅读 · 0 评论 -
指针与常量
指针与常量被指向对象的修饰-*-指针本身的修饰1. 常量指针被指向的对象是常量,又叫常指针形式 : const int* or int const*指向可以修改,值不可以修改2. 指针常量指针本身是常量形式 : int *const必须在定义时赋值指向不可以修改,值可以修改3. 指向常量的常指针指针式常量,指向的对象也是常量形式:const int* const or int const* const指向和值均不可以修改const 函数不能对其数据成员修改原创 2020-05-28 14:28:47 · 113 阅读 · 0 评论