#include<stdio.h>
int main()
{
volatile const int a =100;
volatile const int b =200;
int* p = (int*)&a;
*p = 123;
p = (int*)&b;
*p = 456;
printf("%d %d",a,b);
//使用g++编译器编译输出是100,200
//使用gcc编译器编译输出是123,456
//因为c++编译器做了优化,把const变量直接用常量值代替了
//为了防止出现这种情况
//volatile const int a =100;
//volatile const int b =100;
//volatile关键字 表示每次都要从内容中取值
return 0;
}
相关文章
- 09-23final关键字修饰的变量
- 09-23关于final关键字
- 09-2325.static关键字
- 09-23static 关键字
- 09-23New关键字的学习和总结
- 09-23this关键字_韩顺平听课笔记
- 09-23重写 final关键字 多态调用子类特有的属性及行为(向上向下转型)
- 09-23robotframework中的用evaluate关键字进行运算(随机数+转换+运算)
- 09-23SeleniumLibrary4.5.0 关键字详解(十)
- 09-237 static关键字