第一种用法
修饰局部变量
void test1(){
**volatile const int a=100;**
cout<<"a="<<a<<endl;
*int *p=(int *)&a;
*p=888;*
cout<<"a="<<a<<endl;
cout<<"*p"<<*p<<endl;
printf("&a=%p,%p\n",&a,p);
};
第二种用法
void test2(){
**int b=100;
const int a=b;**
int *p=(int *)&a;
*p=888;
cout<<"a="<<a<<endl;
cout<<"*p"<<*p<<endl;
printf("&a=%p,%p\n",&a,p);
};
第三种用法
struct test{
int a=100;
int b=200;
char c='a';
};
void test3(){
const test test1={100,200,'c'};
cout<<test1.a<<test1.b<<test1.c<<endl;
*test *p=(test *) &test1;*
p->a=200;
p->b=300;
p->c='e';
cout<<test1.a<<test1.b<<test1.c<<endl;
};
结果