指针-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既修饰指针,又修饰常量

 

posted @ 2021-08-02 19:05  毋纵年华  阅读(33)  评论(0)    收藏  举报