内存四区分配图
栈区 堆区
| | |----------------|
| | |________________|
| |
| | 全局区
| | |----------------|
| | | "变量" |
| | |________________|
| |
a|0Xfff23|
|_____| 代码区
|-----------------|
|_________________|
a的指针指向全局区 a->"变量"
int main(void)
{
char *a = NULL;
a = "变量";
printf("%#X,a:%s\n",&a, a);
getchar();
return 0;
}
int main(void)
{
00964180 push ebp
00964181 mov ebp,esp
00964183 sub esp,0D0h
00964189 push ebx
0096418A push esi
0096418B push edi
0096418C lea edi,[ebp-0D0h]
00964192 mov ecx,34h
00964197 mov eax,0CCCCCCCCh
0096419C rep stos dword ptr es:[edi]
0096419E mov eax,dword ptr [__security_cookie (0968024h)]
009641A3 xor eax,ebp
009641A5 mov dword ptr [ebp-4],eax
char *a = NULL;
009641A8 mov dword ptr [a],0
a = "变量";
009641AF mov dword ptr [a],offset string "\xb1\xe4\xc1\xbf" (0966B30h)
printf("%#X,a:%s\n",&a, a);
009641B6 mov eax,dword ptr [a]
printf("%#X,a:%s\n",&a, a);
009641B9 push eax
009641BA lea ecx,[a]
009641BD push ecx
009641BE push offset string "%#X,a:%s\n" (0966BDCh)
009641C3 call _printf (0961325h)
009641C8 add esp,0Ch
getchar();
009641CB mov esi,esp
009641CD call dword ptr [__imp__getchar (096916Ch)]
009641D3 cmp esi,esp
009641D5 call __RTC_CheckEsp (096111Dh)
return 0;
009641DA xor eax,eax
总结指针是的一个地址指向的问题