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

Suppose that p is a value parameter ot type int*. What happens when a function d

ID: 3665206 • Letter: S

Question

Suppose that p is a value parameter ot type int*. What happens when a function does an assignment to *p When should a pointer parameter be a reference parameter Suppose that an array is passed as a parameter. How does this differ from the usual use of a value parameter Write the prototype tor a function called make_ intarray. The function takes two reference parameters: a pointer that will be used to point to the array,and size_t data type to indicate the size of the array.Write a function with one reference parameter that is a pointer to an integer. The function allocates a dynamic array of n integers, making the pointer point to this new array. It then fills the array with 0 through n - 1.Why do average and compare on page 175 use the keyword const with the data array, but f fill_array does not Write a function that copies n elements from the front of one integer array to the front of another. One of the arrays should be a const parameter, and the other should be an ordinary array parameter.Describe in English the behavior of the program in Figure 4.7.

Explanation / Answer

8. if a pointer is passed by value, then although the pointer itself is not affected by changes made to the corresponding formal parameter, the object pointed by the pointed can be changed.

example:

In this example given here., f's parameter is passed by value. Therefore, the assignment p = NULL; in f has no effect on variable q in main (since f was passed a copy of q, not q itself). However, the assignment *p = 5: in f, does change the value pointed to by q.

9.A pointer parameter must be a reference parameter when the actual parameter itself is passed . Therefore, any changes made to the formal parameter do affect the actual parameter.The changes made to the formal paramter within the function will be reflected to the parameter passed to the function .So it changes the value of both the pointers here.

10.Array is always passed as a reference. The changes made to the array within the function will be reflected to the array that is passed as arguement to the function while being called.example:

Although f's parameter looks like it is passed by value (there is no &), since it is an array it is actually passed by reference, so the assignment to A[0] is really assigning to B[0], and the program prints 5 (not 2).

11.

void make_intarray( (int (*pArray)[FIXED_SIZE]),int size_t);

12.

int *A=malloc(n*sizeof(int));

if(A!=NULL)

{for(int i=0;i<n;i++)

A[i]=0;

This will initialize all the elements to 0

or we can use this

for(i=0;i<n;i++)

*(A+1)=0;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote