Write a function which accepts an int array and the number of elements in the array as two parameters.  The function should dynamically create a new int array that is one element larger than the argument array.  Element 0 of the new array should contain size, i.e. the number of elements in the argument array.  Element 0 of the argument array should be copied to Element 1 of the new array, Element 2 of the argument array should be copied to Element 1 of the new array, etc.  The function should return a pointer to the new array and should not modify the argument array.  You may assume that the argument array contains at least one valid element and size is the number of elements in the array.  You do not need to demonstrate calling this function.   Example: if a[] is {2, 7, 4}, and size is 3, the function should return a pointer to a new array with 4 elements containing {3, 2, 7, 4}. int *counter(int a[], int size)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 28SA
icon
Related questions
Question

Write a function which accepts an int array and the number of elements in the array as two parameters.  The function should dynamically create a new int array that is one element larger than the argument array.  Element 0 of the new array should contain size, i.e. the number of elements in the argument array.  Element 0 of the argument array should be copied to Element 1 of the new array, Element 2 of the argument array should be copied to Element 1 of the new array, etc.  The function should return a pointer to the new array and should not modify the argument array.  You may assume that the argument array contains at least one valid element and size is the number of elements in the array.  You do not need to demonstrate calling this function.

 

Example: if a[] is {2, 7, 4}, and size is 3, the function should return a pointer to a new array with 4 elements containing {3, 2, 7, 4}.

int *counter(int a[], int size)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning