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

Refer to the following variables for all parts of this problem #1: int a [] = {5

ID: 3560199 • Letter: R

Question

Refer to the following variables for all parts of this problem #1: int a [] = {5, 10, 15, 20}; int *p = a; Show the values of each of the following expressions, or write ILLEGAL if the expression is not legal for these variables: *P *(p + 2) *p + 2 *(a + 2) v. p - a Using p instead of a, and without using any index variable like i, write a loop structure that prints all four values of the array a. Hints: loop as long as p is less than a + 4, dereference p inside the loop, and increment p at the end of the loop.

Explanation / Answer

int a[] ={5, 10, 15, 20};
int *p = a;

i) *p = 5; // p points base address of array so p hold first element.
ii) *(p+2) = p[2] = 15; // this is nothing but p[2].
iii) *p+2 = 5+2 = 7 // adding 2 to first element of array.
iv) *(a+2) = a[2] = 15; // accessing third element of array.
v) p-a = 0;

// loop using p with out any index variable.

while(p<a+4)
{
printf("%d",*p);
p++;
}

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