#include "stdio.h"
#include "cstring"
using namespace std;
int main(){
int a=248;
int b=4;
printf("%d\n",b);
const int *d=&a;//常量指针,常量a不能改变,但指针的目标可变---const在int左右,作用相同
d = &b;//right
printf("%d\n",*d);
//*d = b;---error
int *const e=&b;//指针常量,指针的目标(只能指向b)不能改变,但目标的值b可变
//e=34;---error
*e = 34;
printf("%d\n",b);
return 0;
}
常量指针与指针常量
最新推荐文章于 2023-09-01 14:56:34 发布