Question: In this lab, you will be given a program that compiles but does not run successfully. When you try to run it, you should get

In this lab, you will be given a program that compiles but does not run successfully. When you try to run it, you should get the message Segmentation fault. Note that no indication is given as to where the program failed. Using the gdb debugger, try to locate where the seg fault occurs. Then fix the errors in broken.c and answer the questions.

1) What was the value of the variable "search" at the time of the seg fault?

2) What was the value of the variable "i" at the time of the seg fault?

3) What are the values in the "table" array?

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

// broken.c //

#include #include

int main( void ) { int i = 0, count = 0, search = 1, found = 0; int number = 5; int table[10];

table[0] = number; printf( "table[%i]: %i ", count, table[count] );

count = 1; while( count < 10 ) { table[count] = number++ * 2; printf( "table[%i]: %i ", count, table[count] ); count++; }

while( search = 1 ) { if( table[i++] == 11 ) { search = 0; found = i - 1; } if( count == i ) { search = 0; } }

if( found ) printf( "The number 11 is in the table at location: %d ", found ); else printf( "The number 11 is not in the table. " );

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!