本帖最后由 jackz007 于 2022-8-19 18:19 编辑
用一个循环把它们的数值都打印出来一看不就一目了然了。#include <stdio.h>
int main(void)
{
int i , a[5] = {1, 3, 5} ;
printf("%d" , a[0]) ;
for(i = 1 ; i < 5 ; i ++) printf(",%d", a[i]) ;
printf("\n") ;
}
这是 main() 函数对应的反汇编代码00401350 /$ 55 push ebp
00401351 |. 89E5 mov ebp, esp
00401353 |. 83E4 F0 and esp, FFFFFFF0
00401356 |. 83EC 30 sub esp, 30
00401359 |. E8 52060000 call 004019B0
0040135E |. C74424 18 00000000 mov dword ptr [esp+18], 0 ; | <--- a[0] = 0
00401366 |. C74424 1C 00000000 mov dword ptr [esp+1C], 0 ; | <--- a[1] = 0
0040136E |. C74424 20 00000000 mov dword ptr [esp+20], 0 ; | <--- a[2] = 0
00401376 |. C74424 24 00000000 mov dword ptr [esp+24], 0 ; | <--- a[3] = 0
0040137E |. C74424 28 00000000 mov dword ptr [esp+28], 0 ; | <--- a[4] = 0
00401386 |. C74424 18 01000000 mov dword ptr [esp+18], 1 ; | <--- a[0] = 1
0040138E |. C74424 1C 03000000 mov dword ptr [esp+1C], 3 ; | <--- a[1] = 3
00401396 |. C74424 20 05000000 mov dword ptr [esp+20], 5 ; | <--- a[2] = 5
0040139E |. 8B4424 18 mov eax, dword ptr [esp+18] ; |
004013A2 |. 894424 04 mov dword ptr [esp+4], eax ; |
004013A6 |. C70424 24304000 mov dword ptr [esp], 00403024 ; |ASCII "%d"
004013AD |. E8 6E080000 call <jmp.&msvcrt.printf> ; \printf
004013B2 |. C74424 2C 01000000 mov dword ptr [esp+2C], 1
004013BA |> 837C24 2C 04 /cmp dword ptr [esp+2C], 4 ; |
004013BF |. 7F 1F |jg short 004013E0 ; |
004013C1 |. 8B4424 2C |mov eax, dword ptr [esp+2C] ; |
004013C5 |. 8B4484 18 |mov eax, dword ptr [esp+eax*4+18] ; |
004013C9 |. 894424 04 |mov dword ptr [esp+4], eax ; |
004013CD |. C70424 27304000 |mov dword ptr [esp], 00403027 ; |ASCII ",%d"
004013D4 |. E8 47080000 |call <jmp.&msvcrt.printf> ; \printf
004013D9 |. 834424 2C 01 |add dword ptr [esp+2C], 1
004013DE |.^ EB DA \jmp short 004013BA
004013E0 |> C70424 0A000000 mov dword ptr [esp], 0A ; |
004013E7 |. E8 3C080000 call <jmp.&msvcrt.putchar> ; \putchar
004013EC |. B8 00000000 mov eax, 0
004013F1 |. C9 leave
004013F2 \. C3 retn
从中可以看出,程序先把 a[] 的所有 5 个元素初始化为 0 值,然后,再分别为 a[0]、a[1]、a[2] 赋值为 1、3、5,所以,a[3] 的值一定是 0。 |