Question: simple c++ Pointers questions. A program includes the following variable declarations: double d1, d2; double *pd1,*pd2; List the output produced by the following code sample.

simple c++ Pointers questions.

A program includes the following variable declarations: double d1, d2; double *pd1,*pd2; List the output produced by the following code sample. In addition, using the examples from class, draw a memory diagram showing the 4 variables d1, d2, pd1 and pd2. Make sure the pointers have a link to the addresses they point to! Draw these diagrams to show the memory state as things change.

Code Sample

Output Generated By The Program

Memory Diagram As Things Change

d1 = 12.4; d2 = 8.9; pd1 = &d1; pd2 = &d2;

*pd1 = *pd2; *pd2 = 41.6; d2 = 13.4;

cout

simple c++ Pointers questions. A program includes the following variable declarations: double

4. For each variable listed on the left, determine whether that variable must deleted to prevent memory problems. If so, state the appropriate delete statement necessary to destroy the dynamic variable and return the memory it uses to the heap so that other variables may use this memory. Please assume that the following constant declarations have been made: const int SIZE = 100;

Dynamic Variable Declaration

Must Be Delete( ) 'ed?

Appropriate delete( ) Statement

char * c = new char(b); yes no
int i( 7 ); yes no
double * d = new double( 12.1 ); yes no
Student * s = new Student(you); yes no
double doubleArray [ SIZE ]; yes no
int *intArray = new int[ 5 ]; yes no

d1 12.4 d2 8.9 pd2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!