Question: (C++) Previous answer code did not work nor did it help, there is no fixed pointer values in the program. Write a program that (1)
Write a program that (1) declares and initializes two int variables and two double variables. Next, (2) declare one pointer to each type (i.e int iPtr, double* dPtr), and initialize each with the address of one of its corresponding variables from (1). Do the following operations: (a) print out the values of the pointers (i.e, the memory addresses that the pointers hold) (b) print out the addresses of the first double and int that the pointers point to (using the address-of operator, &.these addresses had better match the addresses in part (a), above!) (c) print out the values of the first double and int, directly (d) print out the values of these same two variables indirectly (i.e. by dereferencing their pointers) (e) change the value of these two variables, indirectly (i.e. by dereferencing their respective pointers). Print them out directly to prove they've changed. (0 print out the values of the other second double and int directly (declared and initialized in (1), above) (g) change the pointers to point to these second two variables and print out the new (IDaddresses and the (2)values (indirectlhy) of the variables that the pointers now contain. Pointer reminders: declaring and initializing a pointer (of type int, in this example): int iPtr GanInt; // use the address-of operator to get anInt's address . access a variable, indirectly, by dereferencing a pointer to it: double d! 5.6789; double dPtr &d1; // us the address-of operator to get di' s address double d2 *dPtr; /1 set d2 equal to 5.6789 by dereferencing a ptr to di *dPtr 5.0; // set dl equal to 5.0 by dereferencing a ptr to di
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
