Answer to Question #198317 in C++ for Aqib Saeed

Question #198317

For each of the following, write a single statement that performs the specified task. Assume

that double precision variables value1 and value2 have been declared and value1 has been initialized to 0.7254.

a) Declare the variable dPtr to be a pointer to an object of type double.

b) Assign the address of variable value1 to pointer variable dPtr.

c) Print the value of the object pointed to by dPtr.

d) Assign the value of the object pointed to by dPtr to variable value2.

e) Print the value of value2.

f) Print the address of value1.

g) Print the address stored in dPtr. Is the value printed the same as value1’s address? 


1
Expert's answer
2021-05-25T10:48:30-0400
#include <iostream.h>
using namespace std;
int main() 
{

double value1;

double value2=20.4568;
(a) double* dPtr;
(b) dPtr =&value1;
(c) cout<<*dPtr<<"\n";
(d) value2=*dPtr;
(e) cout<<value2<<"\n";
(f) cout<<&value1<<"\n"; //OR
    cout<<dPtr<<"\n"; //BOTH ARE SAME
(g) cout<<dPtr<<"\n";
    cout<<&value1;
    // ANSWER:- YES, BOTH ARE SAME
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog