Strawberry
Strawberry

Reputation: 67868

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?

Upvotes: 0

Views: 664

Answers (1)

Mahesh
Mahesh

Reputation: 34625

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

Upvotes: 2

Related Questions