1、字符串数组与字符串
//字符数组 char arr[6] = {'A','B','C','D','E','F'}; //字符串 char names[] = "ABCDE";
反汇编代码如下:
0040D4B0 push ebp 0040D4B1 mov ebp,esp 0040D4B3 sub esp,54h 0040D4B6 push ebx 0040D4B7 push esi 0040D4B8 push edi 0040D4B9 lea edi,[ebp-54h] 0040D4BC mov ecx,15h 0040D4C1 mov eax,0CCCCCCCCh 0040D4C6 rep stos dword ptr [edi] 0040D4C8 mov byte ptr [ebp-8],41h //A 0040D4CC mov byte ptr [ebp-7],42h //B 0040D4D0 mov byte ptr [ebp-6],43h //C 0040D4D4 mov byte ptr [ebp-5],44h //D 0040D4D8 mov byte ptr [ebp-4],45h //E 0040D4DC mov byte ptr [ebp-3],46h //F 0040D4E0 mov eax,[string "ABCDE" (00422fa8)] 0040D4E5 mov dword ptr [ebp-10h],eax 0040D4E8 mov cx,word ptr [string "ABCDE"+4 (00422fac)] 0040D4EF mov word ptr [ebp-0Ch],cx
字符数组的反汇编中内存中的数据:
字符串在内存的表现为:结尾多了00,编译器在字符串后边加了 00 作为字符串的结束标记
论证结论:
char arr[6] = {'A','B','C','D','E','