1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Phoenix [80]
2 years ago
8

5. Write few lines of code that creates two arrays with malloc. Then write a statement that can create a memory leak. Discuss wh

y you think your code has a memory leak by drawing the status of the memory after you use malloc and the line of the code you claim that creates a memory leak.
Computers and Technology
1 answer:
Darina [25.2K]2 years ago
3 0

Answer:

 // function with memory leak  

void func_to_show_mem_leak()  {  

int *pointer;

pointer = malloc(10 * sizeof(int));

*(pointer+3) = 99;}  

 

// driver code  

int main()  

{  

    // Call the function  

   // to get the memory leak  

   func_to_show_mem_leak();  

     return 0;  }

Explanation:

Memory leakage occurs when programmers allocates memory by using new keyword and forgets to deallocate the memory by using delete() function or delete[] operator. One of the most memory leakage occurs by using wrong delete operator. The delete operator should be used to free a single allocated memory space, whereas the delete [] operator should be used to free an array of data values.

You might be interested in
Create a static method called fillArray, which takes an integer array as an input parameter, along with an integer initial value
JulijaS [17]

Answer:

public class print{

   

   public static void fillArray(int[] arr, int initialValue){

       

       int n = arr.length;

      for(int i=0;i<n;i++){

          arr[i] = initialValue++;

      }

       for(int i=0;i<n;i++){

           System.out.print(arr[i]+" ");

      }

       

   }

    public static void main(String []args){

       

        int[] array = new int[5];

        int initialValue =3;

       

        fillArray(array,initialValue);

       

    }

}

Explanation:

Create the function with two parameter first is array and second is integer.

Then, declare the variable and store the size of array.

Take the for and fill the array from the incremented value of initialValue  by 1 at every run of loop.

After loop, print the element of the array.

Create the main function which is used for calling the function and also declare the array with size 5 and initialValue with 3. After that, call the function with this argument.

3 0
3 years ago
A buffer storage that improve computer performance by reducing access time is​
kvasek [131]
Cache memory

Hope it helps
4 0
3 years ago
The technical relationship between inputs and outputs, which is needed to understand the difference between the short run and th
MrRa [10]
<span>The technical relationship between inputs and outputs, which is needed to understand the difference between the short run and the long run, is called a production function.

Hope I helped ;)
</span>
3 0
3 years ago
Create two classes. The first, named Sale, holds data for a sales transaction. Its private data members include the day of the m
olya-2409 [2.1K]

Answer:

A C++ program was used in creating two classes. the code is stated below.

Explanation:

Solution

The C++ program is executed below:

#include<iostream>

using namespace std;

//declare class (will be define later)

class Salesperson;

//class Sale

class Sale

{

  //private members of class

  private:

      string day;

      double amtOfSale;

      int salesPersonId;

 //public methods

  public:

      //constructor that takes day,amount of sale and salesPersonId as parameters

      Sale(string date,double sale,int id)

      {

          //set the private members to the initial values passed

          day=date;

          amtOfSale=sale;

          salesPersonId=id;

      }    

      //declare a friend function that takes objects of the two classes as parameters

      friend void display(Sale,Salesperson);

};  

//define class Salesperson

class Salesperson

{

  //private members of the class

  private:

      int salesPersonId;

      string lastName;    

  //public methods

  public:

      //constructor that takes name and id as parameters

      Salesperson(int id,string name)

      {

          //set the members of the class with the parameters passed

          salesPersonId=id;

          lastName=name;

      }  

      //declare a friend function that takes objects of the two classes as parameters

      friend void display(Sale,Salesperson);

};

//define the friend funtion

void display(Sale saleObj,Salesperson personObj)

{

  //display the sales info using the objects of the two classes

  cout<<"\nSale #"<<saleObj.salesPersonId<<" on "<<saleObj.day<<" for $"<<saleObj.amtOfSale<<" sold by #"<<personObj.salesPersonId<<" "<<personObj.lastName;

}  

int main()

{

  //create object for Sale class and pass default values

  Sale sObj1("12/25/2016",559.95,103);

  //create object for Salesperson class and pass default values

  Salesperson pObj1(103,"Woods");

 

  //create another object for Sale class and pass default values

  Sale sObj2("11/15/2016",359.95,106);

  //create another object for Salesperson class and pass default values

  Salesperson pObj2(106,"Hansen");

  //using the friend function dislay the sales info

  display(sObj1,pObj1);

  display(sObj2,pObj2);

  return 0;

}

4 0
3 years ago
U
beks73 [17]
8wmX si2 jkkajmid di e2 2i2
3 0
3 years ago
Other questions:
  • Which finger types the highlighted keys on a number keypad? A. Third B. First C. Pinky D. Thumb
    7·2 answers
  • To reduce inflation, the Federal Reserve _____ the money supply. This action also causes the economy to shrink.
    13·2 answers
  • Can someone help me, please
    7·1 answer
  • What is the term for the error caused when one end of an unshielded twisted-pair (UTP) cable is terminated in the T568A configur
    6·1 answer
  • Which of the following is the correct ordering of operating systems, oldest to newest?
    5·2 answers
  • If you go over 255 in RGB by 1 does it reset to 0 or 1
    11·1 answer
  • What dose AUP stand for??????????
    15·2 answers
  • Which of the following are disadvantages of networks? Check all of the boxes that apply.
    14·1 answer
  • In which situations would it be most helpful to filter a form? Check all that apply.
    8·1 answer
  • The photo shows a group of girls reacting to comments they have read about a classmate on a social media site.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!