Function prevent any memory leaks

Assignment Help Basic Computer Science
Reference no: EM132254223

Need help with this homework problem.

Write a void function called transformArray that takes two parameters - a reference to a pointer to a dynamically allocated array of ints, and the size of that array.  The pointer is passed by reference because you want to change the value of the pointer. The function should dynamically allocate an array that is twice as long, filled with the values from the original array followed by each of those values times 2. For example, if the array that was passed in was {4, 2, 5}, then it should be replaced by {4, 2, 5, 8, 4, 10}. The address of the new array should be assigned to the pointer that was passed as a parameter.  The function should prevent any memory leaks. Remember to also prevent memory leaks in the main you use for testing.

For example, it could be used like this:

   int* myArray = new int[3];
   myArray[0] = 4;
   myArray[1] = 2;
   myArray[2] = 5;

   transformArray(myArray, 3);

   for (int i=0; i<6; i++)
      cout << myArray[i] << endl;

   delete []myArray;

The file must be named transformArray.cpp.

Reference no: EM132254223

Questions Cloud

Perform the following calculations assuming : Perform the following calculations assuming that the values are 8-bit decimal integers stored in two's complement format. Be sure to consider the possibility of
Why might management opt for other than the most economic : Using expected value, is it economically better to make or buy the component? Strategically thinking, why might management opt for other than the most economic?
What is the binary representation of the decimal number : 1. What is the binary representation of the decimal number 5.75 assuming the IEE 754 single precision format?
Discuss the weather forecast for the given area : This week's discussion covers topics of weather observations, weather forecasts, and severe weather. Choose any location and discuss the weather forecast.
Function prevent any memory leaks : Write a void function called transformArray that takes two parameters - a reference to a pointer to a dynamically allocated array of ints
Define the practicality of the terror management theory : In the opening of your work, provide an overview of the TMT, noting the critical aspects of the theory, to demonstrate a clear understanding of what the theory.
Create a new string consisting of alternating characters : Given the strings s1 and s2, not necessarily of the same length, create a new string consisting of alternating characters of s1 and s2.
The? punctuated-equilibrium model of group? development : According to the? punctuated-equilibrium model of group? development, the transition sets the revised direction for? ______.
Should the given be viewed as the new normal : Considering the materials for the week, share your thoughts on the effect of media exposure to images from terrorist events. Should these be viewed.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd