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)
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)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images