常量引用、常量指针和指针常量

写这几行就是记录一下这个下面的小知识点

#include <iostream>

using namespace std;

int main()
{
  const int a=3; //只能由常量指针来取其地址
  const int *pt=a;//常量指针
  int * const pt=a;//指针常量
  const int &b=a; //如果变量为常量,要对其引用就必须使用常量引用,这一点同常量指针很相似
  const int &c=b;
  const int &d=c;
  cout<<c<<"  "<<d<<endl;
  return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39785575/article/details/80144049