Given: An array named testScores has already been declared. - size = 5 data type = float. - The array has already been initialized with these values: 77, 88.5, 90, 93, 71.5 Write one statement to declare a pointer named: ptr - In the same statement, assign the address of the testScores array to the pointer.

Respuesta :

Answer:

In the question given, we made  use of c++ coding language for implementation.

Explanation:

From this question given,

we make use of C++ code language

Now, executed  the  steps in c++ in the question. comments were also included for each line in code for better understanding.

C++ Code:

#include <iostream>

using namespace std;

//main function

int main()

{

   //initialize the float array

   float testScores[5] = {77, 88.5, 90, 93, 71.5};

 

    //assign a pointer to the array

   float *ptr = testScores;

 

   //output memory address of first element in array

   cout<<"Memory address of first element using & operator: "<<&testScores[0]<<endl;

   cout<<"Memory address of first element using pointer: "<<ptr<<endl;

 

   //display array elements using pointer in for loop

   cout<<"Array elements using pointer: \n";

   for(int i=0;i<5;i++)

   {

       //dereference pointer using *ptr and

       //add i for subsequent elements in array

       cout<<*(ptr+i)<<endl;

   }

  return 0;

}

ACCESS MORE
EDU ACCESS
Universidad de Mexico