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

a) Declare an integer pointer. b) Use the integer pointer to allocate a dynamic

ID: 3842851 • Letter: A

Question

a) Declare an integer pointer. b) Use the integer pointer to allocate a dynamic array of 30 integers. c) Given the following: double *dp, *dq; double x = 78.9; double y = 23.4; dp = &x; dq = &y; i. What is the value of *dp? ii. Write the C++ code that will swap the values of x and y, WITHOUT USING x and y in your code. iii. Given the following code, write an expression that uses b to copy the third element of the array to the fourth element. DO NOT use a in your answer. float a[5] = {0.0, 1.1, 2.2, 3.3, 4.4}; float *b = &a; [1];

Explanation / Answer

1)int *a;
  

2) a=new int[30];

_____________________

3)i) The value of *dp = 78.9 (as dp is pointing to the address of 'a'.*dp contains the value of 'a')

__________________

3)ii)

//Declare an variable of type double
double temp;
  
//Swap logic
temp=*dp;
*dp=*dq;
*dq=temp;

cout<<x<<endl; // it prints 23.4
cout<<y<<endl; // it prints 78.9

____________________