同一地址的变量如何产生2个不同的值?
考虑一下:
#include <iostream>using namespace std;int main(void){
const int a1 = 40;
const int* b1 = &a1;
char* c1 = (char *)(b1);
*c1 = 'A';
int *t = (int*)c1;
cout << a1 << " " << *t << endl;
cout << &a1 << " " << t << endl;
return 0;}这个输出是:
40 65 0xbfacbe8c 0xbfacbe8c
除非编译器进行优化,否则这对我来说几乎是不可能的。怎么样 ?
温温酱
30秒到达战场
慕标琳琳
森林海
随时随地看视频慕课网APP
相关分类