指针-const修饰指针

技巧:看const右侧紧跟着的是指针还是常量,是指针就是常量指针,是常量就是指针常量。
- const修饰指针 —— 常量指针

点击查看代码
#include<iostream>
#include<string>
using namespace std;
int main(){
int a = 10;
int b = 20;
const int *p = &a;
p = &b;
cout << *p << endl;
system("pause");
return 0;
}
- const修饰常量 —— 指针常量

- const既修饰指针,又修饰常量


浙公网安备 33010602011771号