C++ Question Write and test a function that is passed an array of n pointers to
ID: 3794529 • Letter: C
Question
C++ Question Write and test a function that is passed an array of n pointers to floats and returns a newly created array that contains those n float values. float* translate (float* p [ ], int n) C++ Question Write and test a function that is passed an array of n pointers to floats and returns a newly created array that contains those n float values. float* translate (float* p [ ], int n) C++ Question Write and test a function that is passed an array of n pointers to floats and returns a newly created array that contains those n float values. float* translate (float* p [ ], int n) C++ Question Write and test a function that is passed an array of n pointers to floats and returns a newly created array that contains those n float values. float* translate (float* p [ ], int n)Explanation / Answer
// declare function
float* translate(float* p[], int n)
{
float* const a = new float[n];
//here a is pointing to the beginning of array and this pointer stored in a cannot be changed.
for ( int i=0; i<n; i++) // for n array elements
{
a[i] = *p[i]; // store the value at pointer address into array a
return a; // returning the array of float values stored in array a
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.