Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

8 8 .

Answered: 1 week ago