4. Each of the following routines contains a significant error in its use of pointers. Describe the error in each fragment. Indicate how each error can be fixed. Line numbers have been added as a convenience. Note that the code may compile and run, but that does not mean it is free of errors. (a) 01 02 03 04 05 06 07 08 09 10 11 12 13 int *min(int a, int b) { int theMin; theMin=a; if (b

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
4. Each of the following routines contains a significant error in its use of pointers. Describe the error in
each fragment. Indicate how each error can be fixed. Line numbers have been added as a convenience.
Note that the code may compile and run, but that does not mean it is free of errors.
(a)
01
02
03
04
05
06
07
08
int *min(int a, int b) {
int theMin;
theMin=a;
if (b<a) theMin=b;
return &theMin;
}
main() {
09
10
11
12
13 }
int *theMin;
int a=5;
int b = 7;
theMin-min(a, b);
printf("The min of %d and %d is %d\n", a, b, *theMin);
Transcribed Image Text:4. Each of the following routines contains a significant error in its use of pointers. Describe the error in each fragment. Indicate how each error can be fixed. Line numbers have been added as a convenience. Note that the code may compile and run, but that does not mean it is free of errors. (a) 01 02 03 04 05 06 07 08 int *min(int a, int b) { int theMin; theMin=a; if (b<a) theMin=b; return &theMin; } main() { 09 10 11 12 13 } int *theMin; int a=5; int b = 7; theMin-min(a, b); printf("The min of %d and %d is %d\n", a, b, *theMin);
Expert Solution
Step 1

Given code:

01 int *min(int a, int b) {
02 int theMin;
03 theMin=a;
04 if (b<a) theMin=b;
05 return &theMin;
06 }
07 main(){
08 int theMin;
09 int a=5;
10 int b = 7;
11 theMin=min(a, b);
12 printf("The min of %d and %d is %d\n", a,b,*theMin);
13 }

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education