Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Declare a double pointer. Allocate new memory for it and assign it a value of

ID: 3887300 • Letter: 1

Question

1) Declare a double pointer. Allocate new memory for it and assign it a value of 36.7.  Remember, you are assigning a value to the memory location, don't assign 36.7 as the address!

2) Complete the following program as instructed in the comments

int kidsAge=11, *papaAge, *familyAges[2];

//a) dynamically allocate an int and assign the location to papaAge

papaAge= __________________________________________;

//b) Assign 35 to papaAge (the value 35, NOT the memory location 35!)

___________________ = 35;


//c) Assign element 0 of familyAges to papaAge

____________________________ = papaAge;


//d) Assign element 1 of familyAges to address of kidsAge

__________________________________________________;

//e) Write code to efficiently add 5 to every element of familyAges (that is, the value of kidsAge should be 16, and papaAge 40.

_____________________________________________



_____________________________________________


_____________________________________________


_____________________________________________

  

3) Make a proper function call using only the variables defined below as arguments. Note that you may need to modify the variables with the operators used in processing pointers, but you must use one of the 3 variables listed below. Also note that you should not try to guess at the implementation of the functions, all you are doing is calling the function properly.

int i=6;

double *doub = new double;

char* exclaim="I've got game!";


a)   void yourGame(char );

b)   void myScore(double *, int);

c)   void myGoodness(char *);

d)   void earlyTime(int);

e)   void lateTime(int*, char*, double, double* );

f)   void e(double);

Explanation / Answer

1.

double *d = new double;

*d = 36.7;

2.

a. papaAge = new int;

b. *papaAge = 35;

c. familyAges[0] = papaAge;

d. familyAges[1] = &kidsAge;

e. for(int i = 0;i<2;i++)
*familyAges[i] = *familyAges[i] + 5;

3.

a)   void yourGame(char );

yourGame(*exclaim);

b)   void myScore(double *, int);

myScore(doub,i);

c)   void myGoodness(char *);

myGoodness(exclaim);

d)   void earlyTime(int);

earlyTime(i);

e)   void lateTime(int*, char*, double, double* );

lateTime(&i,exclaim,*doub,doub);

f)   void e(double);

e(*doub);