Hello!
I am learning debugging with gdb. I have found this video on youtube
http://www.youtube.com/watch?v=bAZTd769y8E
Following the example, I am trying to run debugger, but it doesn't display a for loop.
These are my steps from the Terminal:
Code:
(gdb) l
10 d = -1;
11
12 for (; d <= (TOTAL_ELEMENTS - 2); d++)
13 printf("%d\n", array [d + 1]);
14
15 return 0;
16 }
(gdb) break main
Note: breakpoint 1 (disabled) also set at pc 0x100000e74.
Breakpoint 2 at 0x100000e74: file debug1.c, line 7.
(gdb) r
Starting program: /Users/Alla/CS50/TextBook/kandr/exercises/debug1
Breakpoint 2, main () at debug1.c:7
7 int array[] = {23, 34, 12, 17, 204, 99, 16};
(gdb) n
10 d = -1;
(gdb) n
15 return 0;
(gdb)
Here is the intentionally buggy program (example from youtube
video):
Code:
#include <stdio.h>
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int main(void)
{
int array[] = {23, 34, 12, 17, 204, 99, 16};
int d;
d = -1;
for (; d <= (TOTAL_ELEMENTS - 2); d++)
printf("%d\n", array [d + 1]);
return 0;
}
Please, help me to understand why I get to line 15 return 0 instead
of line 12 which is a for loop?
Thank you!