关于c++volatile变量的地址问题
想请教一下大牛们,为什么cout volatile变量的地址输出会是1呢,但是printf输出就是正常的?
例如:
int main()
{
volatile int m = 4;
int *n = const_cast<int*>(&m);;
*n = 3;
{
volatile int m = 4;
int *n = const_cast<int*>(&m);;
*n = 3;
printf("%08x %d\n", &m ,m);
cout << &m << ' ' << m << endl;
cout << n << ' ' << *n << endl;
return 0;
}
cout << &m << ' ' << m << endl;
cout << n << ' ' << *n << endl;
return 0;
}
输出
00bff950 3
1 3
00BFF950 3
#C++工程师#00bff950 3
1 3
00BFF950 3