开发者

GDB: Why can I not print this?

(gdb) print argv[1]
$5 = 0xbffffb1d "hello"
(gdb) step
21     sz = strlen(argv[1]) + 1;
(gdb) print sz
$6 = 0
(gdb) printf "%s开发者_运维知识库", sz
Cannot access memory at address 0x0
(gdb) printf "%i", sz
0

I am expecting 4 in sz, why is it coming out as 0?


I am not sure why you are expecting 4. You get 5 from strlen(argv[1]) because hello has 5 characters. And then you are adding 1 to it which is why the answer is 6.

sz = strlen(argv[1]) + 1; // 5 + 1 = 6
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜