网站培训视频,python 电商网站开发,wordpress主题修改导航链接,建设云购网站文章目录 一、const函数的作用 int a 10;
int *p ;
p a;从上面的代码分析#xff0c;p 存放的就是a的地址#xff0c; *p 存放的就是 a 的值。
一、const函数的作用
一旦使用了const函数修饰一个变量#xff0c;那么这个变量就无法变化了。 所以下面三种情况#… 文章目录 一、const函数的作用 int a 10;
int *p ;
p a;从上面的代码分析p 存放的就是a的地址 *p 存放的就是 a 的值。
一、const函数的作用
一旦使用了const函数修饰一个变量那么这个变量就无法变化了。 所以下面三种情况
const int *p;
int const *p;
int * const p;const int *p 和 int const *p 是一样的所以这里只分析 int const *p; 和 int * const p;
const *p 修饰的是 * p而 * p存放的是对应地址的值所以这里我们不能修改对应地址的值但是可以修改p的地址。
#include stdio.h
int main()
{int a 10;int b 10;int const*p a;*p b; // 这里会报错
}告诉你*p是不可以被修改的。 *p存放的是变量的值 所以这个时候变量的值是不能被改变的。
#include stdio.h
int main()
{int a 10;int b 10;int * const p a;*p b;p b;
}更换写法过后这个错误就不存在了。但是这个时候回告诉你 p 是一个不可修改的值。 p存放的是一个地址这个时候地址不能被修改的