字符指针:
c代码:
char* p = "test";
反汇编代码:
mov dword ptr [p],offset string "test" (41573Ch)
通过查看汇编,可以清楚的看到字符指针实际上是将常量字符串的地址赋值给了变量p。
字符数组:
c代码:
char p[] = "test";
反汇编代码:
mov eax,dword ptr [string "test" (41573Ch)]
mov dword ptr [ebp-10h],eax
mov cl,byte ptr ds:[415740h]
mov byte ptr [ebp-0Ch],cl
而字符数组实际上是将常量字符串通过mov指令拷贝到了栈区,由于存在‘/0’字符的存在,在该反汇编代码中进行了两次拷贝,第一次拷贝了4个字符,第二次拷贝了1个字符。