C++——常指针

版权声明:都是平时的作业 欢迎评论点赞哦 https://blog.csdn.net/Getugly/article/details/85138446

#include<iostream.h>

int main()
{
	int a=1;                //普通变量     
    const int b=2;          //常值变量

	int *const pa=&a;  //常指针
	//常指针只能指向普通变量,并且必须要对它初始化
    //	错误:pa=&b; 常指针不能指向常值变量;
	(*pa)++;  //可以对常指针指向的普通变量的值进行修改;
	//pa++;  //不能对常指针的指向进行修改
	
	return 0;

}

猜你喜欢

转载自blog.csdn.net/Getugly/article/details/85138446