#include "pch.h"
#include
using namespace std;
int func( const int * const p)
{
int a = 9;
a += *p;
return *p;
}
int main()
{
int x = 10;
cout << func(&x);
}
#include "pch.h"
#include
using namespace std;
int func( const int * const p)
{
int a = 9;
a += *p;
return *p;
}
int main()
{
int x = 10;
cout << func(&x);
}
const int * const的意思是:一个指向const int的不可变化的指针(指针指向的地址不可变,地址中的内容也不可变)。
在函数参数中加const的意义是:在编译期就检查有没有改变p或*p的值,如果改变了就直接报错。