
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
![It is best practice to free anything we malloc immediately after the last use of that pointer. Where should we add free invocations in the following code?
int *unsorted (int *array, int length) {
int *a2 = calloc(length, sizeof(int));
int *a3 = calloc(length, sizeof(int));
for(int i=0; i<length; i+=1) a2[i] = array[i];
}
sort_array(a2);
return a3;
// position 1
Therefore, we should free (a3) in which position?
A. position 1
B. position 2
C. position 3
D. position 4
E. position 5
F. position 6
G. We should not free(a3) in this function
// position 2
// position 3
for(int i=0; i<length; i+=1) a3[i] = (array[i]
// position 4
!= a2[i]);
// position 5
// position 6](https://content.bartleby.com/qna-images/question/8f8149c8-eddc-413d-9cd1-3019171cd65e/b98327d6-5f25-4e60-bff9-0fa2a5a9cbe4/qxgk8g_thumbnail.png)
Transcribed Image Text:It is best practice to free anything we malloc immediately after the last use of that pointer. Where should we add free invocations in the following code?
int *unsorted (int *array, int length) {
int *a2 = calloc(length, sizeof(int));
int *a3 = calloc(length, sizeof(int));
for(int i=0; i<length; i+=1) a2[i] = array[i];
}
sort_array(a2);
return a3;
// position 1
Therefore, we should free (a3) in which position?
A. position 1
B. position 2
C. position 3
D. position 4
E. position 5
F. position 6
G. We should not free(a3) in this function
// position 2
// position 3
for(int i=0; i<length; i+=1) a3[i] = (array[i]
// position 4
!= a2[i]);
// position 5
// position 6
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps

Knowledge Booster
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
- javaarrow_forwardWhat transpires when a parameter for an array is sent in with either the ref or out keyword, and the results are observed?arrow_forwardWrite the function lastOf which searches the array a for the last occurance of any value contained in the array b. Returns the index if found. If not found, return -1. arrays.cpp 1 #include 2 3 int lastof(const int a[), int alen, const int b[], int blen) 4 { int res = 0; for (int i = 0; i =0 ; j--) if (b[j] == a[i]) { if(res[1, 9, 4, 5, 1, 5, 1, 12, 8, 11, 2, 11, 7, 8] b1->[7, 5, 9] last0f(al, 14, b1, 3): -1 Expected: 12 al->[1, 9, 4, 5, 1, 5, 1, 12, 8, 11, 2, 11, 7, 8] b2->[7, 7] lastof (al, 14, b2, 2): -1 Expected: 12 a2->[3, 2, 1, 14, 10, 6, 13, 1ө, 11, 13, 14] b2->[7, 7] lastof (a2, 11, b2, 2): -1 Expected: -1 а2->[3, 2, 1, 14, 10, 6, 13, 1ө, 11, 13, 14] b1->[7, 5, 9] last0f (a2, 11, b1, 3): -1 Expected: -1 а2->[3, 2, 1, 14, 10, 6, 13, 10, 11, 13, 14] b3->[11, 2, 1, 15] lastof (a2, 11, b3, 4): -1 Expected: 8 Score 2/5arrow_forward
- public int binarySearch(int[]array, int num) {int low = 0;//low rangeint high = array.length -1; //high range int mid; //mid rangewhile () //while low is less than or equal to high{mid = ; //set middle range to be (low + high) /2if () { //if the array in the middle range = input number//return mid range }elseif () { //if the array in the middle range > input number//set the high value to be the mid value minus 1 }else{//set low value to be mid value plus one } }//return -1 here because that would mean that the number is not found in the loop}arrow_forwardWhat does each line of code mean?arrow_forwardX40: sum3 Given an array containing three ints, return the sum of all the elements. Examples: sum3({1, 2, 3}) -> 6 sum3({5, 11, 2}) -> 18 Your Answer: 1 public int sum3(int[] nums) 2{ 3 4} Check my answer! Reset Next exercisearrow_forward
- Java Netbeansarrow_forwardWe have an array variable ‘var’ int var[4] = {25,20,30,40}; Find the memory address of the first element of in the array: var[0]arrow_forwardGiven the Array declaration below, determine the output: int T[8] = {2, 3, 7, 9, -1, 2, 4, 5}; int x = 5; cout << T[x-2] / T[12-2*x]; int y = -3; cout << pow(T[y+4],T[3-y]);arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education