Pointer basics Declare two type double pointer variables nam
Pointer basics Declare two (type double) pointer variables named d_var and d_array: Write C++ statements to dynamically create a double-precision floating-point variable and store its address in d_var. Also dynamically create an array of 10 double-precision floating-point values and store its address in d_array: Write C++ statements to input a value for d_var (i.e., a value that d_var points to) from the console and then display it: Write C++ statements to initialize the 10 double values in the dynamically allocated array to 1.0: Now write C++ statements to de-allocate the memory (i.e. using the delete operator) pointed by d_var and d_array:
Solution
#include <iostream>
using namespace std;
int main()
{
//a
double *d_var,*d_array;
//b
d_var=new double;
d_array=new double[10];
//c
cout<<\"Enter the value for d_var:\";
cin>>*d_var;
for(int i=0; i<10; i++)
{
*(d_array+i)=1.0;
}
//d
cout<<\"The value of d_var:\"<<*d_var<<endl;
cout<<\"The values of d_array:\"<<endl;
for(int i=0; i<10; i++)
{
cout<< *(d_array+i)<<\" \" ;
}
//e
delete d_var;
delete d_array;
return 0;
}
OUTPUT:
Enter the value for d_var:32
The value of d_var:32
The values of d_array:
1 1 1 1 1 1 1 1 1 1
