Prevent memory leaks in the main

Assignment Help Business Management
Reference no: EM132246665

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;

Reference no: EM132246665

Questions Cloud

How could your company benefit from byod : Management focuses on accountability for how BYOD is managed, addressing risk, compliance, costs, and other liabilities.
Briefly justify your choice and explain how it will solve : Identify the theory that will be used to analyse the case study. The reader should be able to get a clear picture of the essential contents of the study.
Would you focus on forming a centralized government : Eco518: Comparative Economic Systems If you were involved in helping to form the constitution or rules of engagement for a colony that will be set up on Mars.
Accurate representation of cultural specifics : One way that teachers can help to ensure their students understand the different cultures around them is through literature.
Prevent memory leaks in the main : 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
What role did your parents play in sharing literature : What were some of the ways that literature influenced you and helped shape who you are today?
Prevent a user from having access : In linux how could you automatically prevent a user from having access to any files or directories that you create?
Team that scores the most number of points : The winning team is that one that wins the most matches. Note: It is not necessarily the team that scores the most number of points
Identifying a principal-agent problem in your company : Identify a principal-agent problem in your company and evaluate the tools it uses to align incentives and improve profitability.

Reviews

Write a Review

Business Management Questions & Answers

  Reinventing corporations

Many large corporations are now attempting to reinvent themselves. Describe what the biggest challenge in the process is, and why.

  Addresses study plans and logical flow of research

Addresses study plans and logical flow of research - Identify the elements of a concept paper/study plan with references.

  Make a residual plot from the linear regression model

Make a residual plot from the linear regression model you constructed above. How confident are you that the prediction is quite accurate?

  Role of talent management in today organizations

One of the most well-known examples of succession planning and talent management is the process used by General Electric

  Evaluate respective shares of partnership losses

Evaluate respective shares of partnership losses?

  Differences between change in large organizations

The differences may be obvious or subtle. But what do you think are the differences between change in large organizations versus small ones?

  Foundations and challenges in strategic management

foundations and challenges in strategic management walmartin a narrative format discuss walmart from a strategic

  What is the purpose of a performance appraisal

a. What is the purpose of a performance appraisal? b. How can performance appraisals be administered properly to help both the organization and employees?

  Assignment-evaluation of business operations

You are the human resources (HR) manager for a public organization and you are conducting a New Hire Orientation session for all new employees. Last week, you analyzed the organization, including its strengths and weaknesses, as well as its missio..

  Successful ehr implementation story

Talk about successful EHR implementation story either in United Arab Emirates or any other country you prefer to write about.

  Expect the stock to sell for in three years

A). If the coming year's earnings are expected to be $4 per share, at what price will the stock sell? B). What price do you expect the stock to sell for in three years?

  Project charter checklist for expert tips

At a project's initiation, management and stakeholders authorize and approve the work to be done. This process often takes the form of a project charter, which can be either an informal document or a formal contract. In both cases, key stakeholder..

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