Question: Compile and run the following two programs: 1.c and 1_NULL.c Why does the second program crash? fix the problem in the 1_NULL.c program by modifying

 Compile and run the following two programs: 1.c and 1_NULL.c Whydoes the second program crash? fix the problem in the 1_NULL.c program

Compile and run the following two programs: 1.c and 1_NULL.c

Why does the second program crash?

fix the problem in the 1_NULL.c program by modifying the 1 function such that whenever NULL value is used as its first argument during the function call from main function, this function displays a meaningful error message and the program

exits normally.

Tip:

To exit a program, you may use the exit() function. It takes an integer (zero or non-zero) to represent

different exit status. You must include the header file.

- Exit Success is indicated by exit(0) statement which means successful termination of the

program, i.e., program has been executed without any error or interrupt.

- Exit Failure is indicated by exit(1) which means the abnormal termination of the program, i.e.,

some error or interrupt has occurred. We can use different integer other than 1 to indicate

different types of errors. For this program, you may use the exit(1); statement. Because you want to terminate the program due to null pointer error. Make sure that the NULL argument is used as instructed above.

7/|(this 1.c) #include // Function prototype void divisionCallByReference (double *pointerToResult, double x, double y); int main (void) { double numerator, denominator, result; printf("Enter numerator and denominator values: "); scanf("%lf %lf", &numerator, & denominator); divisionCallByReference(&result, numerator, denominator); printf("Result = %f ", result); return 0; } // Function definition void divisionCallByReference (double *pointerToResult, double x, double y) { *pointerToResult x/y; } // This is 1_Null.c| #include // Function prototype void divisionCallByReference (double *pointerToResult, double x, double y); int main (void) { double numerator, denominator, result; printf("Enter numerator and denominator values: "); scanf("%f %lf", &numerator, & denominator); divisionCallBy Reference(NULL, numerator, denominator); printf("Result %f ", result); return 0; } // Function definition void divisionCallByReference (double *pointerToResult, double x, double y) { // TODO : Handle the Null pointer error *pointerToResult = x/y; }

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!