void main()
{
const int i=0;
int *p=(int*)&i;
*p=100;
cout<<&i<<endl;
cout<<p<<endl;
cout<<*p<<endl;
cout<<i<<endl;
}
运行图贴不上来
这是结果:
001aff18
001aff18
100
0
地址一样,结果却不一样。
经论坛达人解释,发现编译器对于cout<<i<<endl; 是直接push 0 的
cout<<i<<endl;
00411486 mov esi,esp
00411488 mov eax,dword ptr [__imp_std::endl (418298h)]
0041148D push eax
0041148E mov edi,esp
00411490 push 0
00411492 mov ecx,dword ptr [__imp_std::cout (41829Ch)]
00411498 call dword ptr [__imp_std::basic_ostream<
char
,std::char_traits<
char
> >::operator<< (4182A0h)]
0041149E cmp edi,esp
004114A0 call @ILT+340(__RTC_CheckEsp) (411159h)
004114A5 mov ecx,eax
004114A7 call dword ptr [__imp_std::basic_ostream<
char
,std::char_traits<
char
> >::operator<< (4182A4h)]
004114AD cmp esi,esp
004114AF call @ILT+340(__RTC_CheckEsp) (411159h)