//pointers using subcript natation // Complete this program with subscript notat
ID: 3571327 • Letter: #
Question
//pointers using subcript natation
// Complete this program with subscript notation for a pointer variable using the pointer name and the pointer to the array
/*
Here are the values in the doubles array using pointer doublePtr:
78.4 34.7 93.5 9.5 2.4
And here they are again using pointer notation with the array name 'doubles':
78.4 34.7 93.5 9.5 2.4
Press any key to continue . . .
*/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int SIZE = 5;
double doubles[SIZE] = { 78.4, 34.7, 93.5, 9.5, 2.4};
cout << "Here are the values in the doubles array using pointer doublePtr: ";
cout << " And here they are again using pointer notation with the array name 'doubles': ";
return 0;
}
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int SIZE = 5;
double doubles[SIZE] = { 78.4, 34.7, 93.5, 9.5, 2.4};
cout << "Here are the values in the doubles array using pointer doublePtr: ";
//pointer doublePtr pointing to doubles array
double *doublePtr = doubles;
/* printing array using pointer doublePtr */
for (int i = 0; i < 5; ++i)
{
cout <<*(doublePtr + i) <<" ";
}
cout << " And here they are again using pointer notation with the array name 'doubles': ";
/ * printing array using array doubles */
for (int i = 0; i < 5; ++i)
{
cout << doubles[i] <<" " ;
}
return 0;
}
/***********OUTPUT********/
78.4 34.7 93.5 9.5 2.4
And here they are again using pointer notation with the array name 'doubles':
78.4 34.7 93.5 9.5 2.4
**********OUTPUT*********/
/* Note : this code has been tested on g++ compiler,Please do ask in case of any doubt,Thanks..!! */
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.