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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started