Predict stops from ignore counts and conditions

A program compiled with gcc -g -O0 contains this loop, with total declared and set to zero just before it:


C
long total = 0;                    /* line 16 */
for (int i = 0; i < 500; i++) {    /* line 17 */
    total += 2 * i;                /* line 18 */
}


In GDB you enter break 18, which creates breakpoint 1, then ignore 1 120, then run. When the program stops, you print i and total. You then enter condition 1 i % 50 == 0 followed by continue, and when the program stops again you print i and total once more.


Give the value of i and the value of total at each of the two stops, each as an integer.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More GDB & Valgrind Questions: