Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// pointers showing address and values in an array // This program shows the val

ID: 3571334 • Letter: #

Question

// pointers showing address and values in an array
// This program shows the value and the address of each element in the array. Use pointer notation.
/*
Here are the values in the doubles array:
0.87 at address 0x61cbe8
0.34 at address 0x61cbf0
0.11 at address 0x61cbf8
0.78 at address 0x61cc00
2.35 at address 0x61cc08
You can see that the address increments by 8 bits.

Press any key to continue . . .
*/

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int SIZE = 5;
double doubles[SIZE] = {0.87, 0.34, 0.11, 0.78, 2.35};

// Use the pointer to display the values in the array.
cout << "Here are the values in the doubles array: ";


cout << "You can see that the address increments by 8 bits. ";
cout << endl;
return 0;
}

Explanation / Answer

#include <iostream>
#include <iomanip>
#include<stdlib.h>
using namespace std;

int main()
{
   const int SIZE = 5;
   double doubles[SIZE] = {0.87, 0.34, 0.11, 0.78, 2.35};
  
   // Use the pointer to display the values in the array.
   double *d;
   d=doubles;
   cout << "Here are the values in the doubles array: ";

//For Printing array
   for(int i=0;i<5;i++)
   cout<<*(d+i)<<endl;

   cout << "You can see that the address increments by 8 bits. ";

// For printing address
   for(int i=0;i<5;i++)
   cout<<(d+i)<<endl;
   cout << endl;
   return 0;
}