Question
C++: Write a function that takes 2 integer pointers that are expected to point to the beginning and end of a sequential block of integer
C++:
Write a function that takes 2 integer pointers that are expected to point to the beginning and end of a sequential block of integer numbers (my prototype for the function looks like this: void reverseData(int *start, int *end)). This function will use pointer arithmetic to swap the order of the numbers in the block (for example, if the block contained the numbers 1, 2, 3, 4, 5, then after the function the block would have the numbers 5, 4, 3, 2, 1). Then do the following:
In your main function, use dynamic memory allocation to create a block of 10 integers, then initialize them 1 - 10 in order. Call the reverse function you wrote earlier using the addresses for the first and last items in the block for the arguments to the function. Next, create a static array of 10 integers initialized 1 - 10. Call the reverse function with the addresses of the first and last elements of the array as the arguments to the function. Does the function operate the same on both groups of numbers? Why or why not?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started