vs2005+win7+release模式内存分配原理
#include <stdio.h>
#include <string.h>
void main (){
char test1[1] = {'d'};
char test2[2] = {'e','e'};
char test3[3] = {'f','f','f'};
char test4[4] = {'g','g','g','g'};
char test5[5] = {'h','h','h','h','h'};
printf("test5 = %d\n", test5);
printf("test1 = %s, test2 = %s,test3 = %s, test4 = %s, test5 = %s", test1, test2, test3, test4, test5);
}
内存如下
0x0012FEF9 2a f5 18 fe ff ff ff ac 26 5b 73 86 10 40 00 f0 20 40 00 2f ff *?.?...?&[s?.@.? @./.
0x0012FF0E 12 00 30 ff 12 00 34 ff 12 00 38 ff 12 00 3c ff 12 00 e4 20 40 ..0...4...8...<...? @
0x0012FF23 00 3c ff 12 00 01 00 00 00 e0 10 40 64 65 65 40 00 66 66 66 00 .<.......?.@dee@.fff.
0x0012FF38 67 67 67 67 68 68 68 68 68 30 40 00 b7 a6 85 6b 04 12 40 00 01 gggghhhhh0@.???k..@..
0x0012FF4D 00 00 00 38 49 24 00 08 2b 24 00 13 a6 85 6b 00 00 00 00 00 00 ...8I$..+$..??k......
0x0012FF62 00 00 00 d0 fd 7f 00 00 00 00 00 00 00 00 58 ff 12 00 18 7b b4 ...??.........X....{?
将printf("test1 = %s, test2 = %s,test3 = %s, test4 = %s, test5 = %s", test1, test2, test3, test4, test5);
注释掉内存如下
0x0012FEF9 1b 63 73 ac 26 5b 73 5e 4c 67 a1 74 33 40 00 01 00 00 00 00 00 .cs?&[s^Lg?t3@.......
0x0012FF0E 00 00 10 00 00 00 00 ff 12 00 02 00 00 00 78 ff 12 00 ed 8c 5a ..............x...??Z
0x0012FF23 73 12 e3 17 d2 fe ff ff ff ac 26 5b 73 32 10 40 00 e4 20 40 00 s.?.??...?&[s2.@.? @.
0x0012FF38 3c ff 12 00 68 68 68 68 68 30 40 00 54 9b 60 a1 af 11 40 00 01 <...hhhhh0@.T?`??.@..
0x0012FF4D 00 00 00 38 49 54 00 08 2b 54 00 e0 9b 60 a1 00 00 00 00 00 00 ...8IT..+T.??`?......
0x0012FF62 00 00 00 b0 fd 7f 00 00 00 00 00 00 00 00 58 ff 12 00 4b 24 44 ...??.........X...K$D
0x0012FF77 f9 c4 ff 12 00 55 16 40 00 a0 45 32 a1 00 00 00 00 94 ff 12 00 ??...U.@.?E2?....?...
为何注释掉printf之后test1,2,3,4等在临近内存中没有出现只有test5?
vs2005+win7+release模式